Validate email textbox

Dear Experts

I am trying to validate email textbox, my blocks are as follows

If textbox is not empty and textbox contains @ then validation must be ok

The block those I used are not working.

Please help me to make my blocks workable

or

Is there any other good way to validate textbox for email.

Regards

you want to use RegEx extension, there is one function called IsEmail ...

couldn't you move the and block to the inner most notch? it'd function the same, since it returns true/false anyways

@aadenboy

Yes you could, I copied the blocks from a much larger password verifier with several layers, and left the extra logic in....

image

1 Like

ChatGPT says:

To validate an email address in MIT App Inventor, you can use a combination of blocks to check if the email address entered by the user meets certain criteria. Here's a step-by-step guide on how to validate an email address:

1. Open your project in MIT App Inventor and navigate to the screen where you want to validate the email address.

2. Drag and drop a "TextBox" component from the "User Interface" palette onto the screen. This will be used for users to enter their email address.

3. Drag and drop a "Button" component from the "User Interface" palette onto the screen. This will be used to trigger the validation process.

4. Switch to the "Blocks" editor by clicking on the "Blocks" button in the top-right corner of the MIT App Inventor interface.

5. Find the "Button" component you added in the "Built-In" palette and locate the "Click" event block. Drag and drop it onto the workspace.

6. Inside the "Click" event block, add a "Text" block from the "Text" palette. Connect it to the "TextBox" component you added earlier. This block will retrieve the text entered in the TextBox.

7. Add a "Text" block from the "Text" palette and connect it to the "Text" block you just added. This will store the email address entered by the user in a variable for further validation.

8. Now, you need to validate the email address using regular expressions. Add an "if" block from the "Control" palette and place it below the previous blocks.

9. Inside the "if" block, add a "Text" block from the "Text" palette and connect it to the "Text" variable block you created earlier.

10. To validate the email address, you can use the "matches" block from the "Text" palette. Connect it to the "Text" block inside the "if" block.

11. Enter the regular expression pattern for email validation in the "matches" block. A commonly used pattern for email validation is:
    ```regex
    ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
    ```

12. If the email address matches the pattern, you can add the desired actions or display a success message. If the email address does not match the pattern, you can display an error message.

13. To display a message, you can use the "Notifier" component. Add a "call Notifier.ShowAlert" block from the "Notifier" palette inside the appropriate section of the "if" block.

14. Customize the error or success message as per your requirements.

15. Finally, test your app by connecting a device or using the emulator to see if the email address validation works as expected.

Remember to customize the validation process and error/success messages based on your specific needs.

But I could not found the Matches in Text in step 10

Where is Matches in Text component?

Please

I don't recommend ChatGPT for coding because


it doesn't really understand what it's doing

anyways, it probably meant one of these blocks
image
image

5 Likes

Why ? For such a simple matter ? (in fact "why anyway?" regardless of simplicity)

ChatGPT doesn't really know what blocks are available in app inventor. But he thinks he knows... tell him that I don't have such a block and he will change his answer. So you have to be able to verify ChatGPT's advice because he often writes stupid things. Artificial intelligence is not the same as unlimited knowledge...

1 Like

ChatBoot....??

Probably based on how often it puts its foot in its mouth.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.