Hi! Using this thread to ask another question on form validation formulas. I’m looking to restrict a field to email addresses only, and an easy way of doing that (while not being perfect) would be to check that the submitted input contains the “@” character. I’ve tried the fomula CurrentValue.Contains("@")
but it just outputs “false” to everything, and right now I’m out of ideas
Hi @Jonas_Faugere,
Go ahead and make a new thread for this question (it can be the same text as you have here) and I’ll answer you there. Make sure to ping me in the new question
Try if(CurrentValue.Contains(“@”),true,false)
@Connor_McCormick you can respond now
Oh, wow, thank you. Do I have the ability to do that yet?
CurrentValue.Find("@") > 0
This will try to find an “@” symbol inside of CurrentValue
. If it does it will return the location in the string, if it doesn’t find it it will return -1
. To be sure that it found an “@” symbol we just check whether the number it returns is greater than 0.
In practice, an email address like “@example.com” isn’t valid because there’s no addressee, so you might want to use CurrentValue.Find("@") > 1
instead.
What if someone types ‘user@’ ?
This is the formula that detects valid URLs:
CurrentValue.startswith(“http://”)
Long story short, there isn’t a good way to recognize valid email addresses. The best way is to require someone to validate their email address by clicking a link in an email they received.
Hello everybody! I found this way of doing it, but as you can see in the link @Connor_McCormick shared, there isn’t an infallible way of recognizing them, so proceed with caution.
If you want a rough approximation to match most email addresses and catch most errors, try this:
CurrentValue.RegexMatch("^[\w-+.]+@[\w-]+.[\w-.]+$")
If you want a more thorough matcher, you can use:
CurrentValue.RegexMatch("(?:[a-z0-9!#%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#%&’+/=?^_`{|}~-]+)|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])")@(?:(?:a-z0-9?.)+a-z0-9?|[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-][a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])+)])")
I wrote the first one; the second one came from here:
Thanks a ton everyone - for making this its own thread and for your super helfpul answers.
@Matthew_Strax-Haber your first formula didn’t seem to have any effect on the field validation for some reason. The second formula seem to work pretty well after some testing — though I’m taking into account those remarks that there’s no sure fire way to validate emails. Still better than nothing!
Yeah, it seems the RegexMatch formula doesn’t work with all regexes. I don’t know why
The fully RFC 822 compliant regex is inefficient and obscure for validate email address because of its length. Fortunately, RFC 822 was superseded twice and the current specification for email addresses is RFC 5322. RFC 5322 leads to a regex that can be understood if studied for a few minutes and is efficient enough for actual use.
If you use HTML5, use this code:
<input type="email" name="email" required placeholder="Enter a valid email address">
Sorry to be picky, but should a " \ " be added before the second to last period in your regexFormula?
Making it: CurrentValue.RegexMatch("^[\w-+.]+@[\w-]+\.[\w-.]+$")
\w-+. ↩︎
Good catch! Should it be \.
within the [\w-+.]
(i.e., [\w-+\.]
) as well?
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.