Hello. I want to have a space for users to enter their email address. I want to make it so that you have to enter an @ sign. What would the validation look like for this? Thanks
Discussion posts and replies are publicly visible
not(
like( ri!emailAddress, "*@*")
)
See how this works
If you'd like a validation to make sure a user enters a syntactically-correct full email address, I have an expression rule that uses only out-of-box features that works rather well which i've posted here in the past, and would be willing to look up and repost for you if needed.
Hello! This works very well. I have one other question. How may I change this code to accommodate a message? For ex: "Please Use '@'"? Thanks
Thank you, Mike, that's very nice of you, I will consider it
In case you or anyone else wants my code for this, here is the current version:
/* Email Address Validation for Appian */ /* Allows the 'name' to contain letters, numbers, plus period and special characters: _ - + ' & % */ /* Allows the 'domain' to contain only letters, numbers, period and dash. */ if( or( isnull(trim(ri!address)), len(trim(ri!address)) > 255, length(split(trim(ri!address), " ")) > 1, count(split(ri!address, "@")) <> 2 ), false(), with( local!userPart: split(trim(ri!address),"@")[1], local!domainPart: split(trim(ri!address),"@")[2], if( or( length(split(local!domainPart, ".")) < 2, contains(split(local!userPart, "."), ""), contains(split(local!domainPart, "."), ""), not(isnull(stripwith(lower(local!domainPart), "abcdefghijklmnopqrstuvwxyz1234567890-."))), not(isnull(stripwith(lower(local!userPart), "abcdefghijklmnopqrstuvwxyz1234567890-._+'&%"))) ), false(), true() ) ) )
Saved as an Expression Rule, this code simply returns True or False, referring to whether a given email address is valid.
If you're only interested in checking for the presence of the "@" in your validation (and validation message), then it's fairly easy to just use standard logic in the Validations: parameter of your text input field.
It would be accomplished with code similar to this:
a!textField( value: ri!email, saveInto: ri!email, validations: { if( not(like(ri!email, "*@*")), "email address must contain an '@' sign.", null() ) } )
Perfect. Thanks
No prob - but just be aware (if it matters for your use case) that this logic will also allow a user to enter a lot of things that are not a valid email address - like "mike@", or "@test", or "mike@@test.com" (and various other incorrect permutations).