Checking for a valid email address

advanced-prototyping

#1

I’m working on an interaction where the user enters an email address, and if it’s invalid, we show an error message. I can either try to mock that up, or I can simply describe the interaction to the engineers, although mocking it up would be clearer.

Is there a way to detect for a valid email address that is not completely onerous?


#2

Given the eternal stream of StackOverflow questions in the Quixotic quest for the one RegExp to rule email validations, I would avoid trying to perfectly implement email validation in Axure. Instead, I’d go with a few basic points to pretty accurately represent it, and then describe the rest.

Here’s a few things (non-exhaustive list) you could include in a condition for email validation (set all conditions must be true):

[ul]
[li]If value [[EmailField.text.indexOf(’@’)]] is greater than or equal to 1 (must contain @ but can’t be first character)[/li][li]If value [[EmailField.text.lastIndexOf(’.’)]] is greater than [[EmailField.text.indexOf(’@’)]] (must be a period after the @, represents a domain being present)[/li][/ul]

I would probably just stick to those two. a@a.a will pass. a@a.a.a will pass. a.a@a.a will pass. @a.a won’t pass. a@a won’t pass. Good enough probably.


Email field validation
#3

Thanks! Just detecting those 2 conditions for validation will totally work, and it looks easy. Much appreciated!


#4

I know this is a bit of an old thread, but I can’t get this to work for the life of me. Do you happen to have an .rp that I could look at. I may entering it wrong.

Thanks!


#5

Make sure you have EmailField (in the example, though it could be any name you want) set up as a local variable in the expression. If you set the local variable to a widget, use LVAR1.text (LVAR1 is the default local variable name, you can change it) or you can set it to Text on Widget and replace LVAR1.text with just LVAR1.

If you have these conditions on cases in an event of the same widget that has the text you’re checking, you can replace EmailField.text with this.text


#6

Perfect! Thanks!


#7

[QUOTE=nkrisc;62198]Make sure you have EmailField (in the example, though it could be any name you want) set up as a local variable in the expression. If you set the local variable to a widget, use LVAR1.text (LVAR1 is the default local variable name, you can change it) or you can set it to Text on Widget and replace LVAR1.text with just LVAR1.

If you have these conditions on cases in an event of the same widget that has the text you’re checking, you can replace EmailField.text with this.text[/QUOTE]

I’ve did per your instructions but I still cannot validate the email :frowning:

This is the file I am working on (small and simple):
Example Form.rp (105 KB)


#8

You set the local variable to “Text on Widget” but then you also used “LVAR1.text”.

Either set the local variable to “Widget” and use “LVAR1.text” or set the local variable to “Text on Widget” and use “LVAR1”


#9

Got it, thank you very much.


#10

Any chance you can share your corrected Example Form.rp file? I looked at your .rp file and I still don’t understand what you need to change in order to make the validation work. Hope to hear from you. Thanks!


#11

Hi mali,

From Nathan’s response, it sounded like Kaske needed to correct the reference to his local variable, LVAR1, which was set to equal the text on a form field.

I believe this screenshot shows (highlighted in orange) what they needed to correct based on the defined local variable:

Can you attach your RP file as well? We’d be happy to take a look. The following tutorial may be a great start, too:

https://www.axure.com/support/training/account-login-tutorial

And here’s more on using local variables:

https://www.axure.com/support/reference/variables#local_variables


closed #12

unlisted #13