Form validation formulas

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 :confused:

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)

1 Like

@Connor_McCormick you can respond now :+1:

1 Like

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.

1 Like

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:

4 Likes

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