isMatch returns always false on a given regex - Mendix Forum

isMatch returns always false on a given regex

0

Hi guys,

I would like to apply a Regex on my string variable. I`m using the isMatch function for that in an IF statement. The problem that i face is that the isMatch returns always false. 

This is my code line on the IF statement isMatch($UserEmail,'[A-Z]'), even though i`ve tried to write it in this format isMatch($UserEmail, '^([A-Z]+)$') and still returns false.

The $UserEmail is in string format like Norbert.Csibi@test.com

(What I’m trying to do is to find at least one upper character in the whole email address)

Many thanks.

asked
4 answers
3

isMatch implicitly adds ^ in front of your regex and $ at the end. So don’t include them since this would result in a regex like ^^[A-Z]$$ thus not finding anything. And [A-Z] always results in false since is does not include @ nore .

Search on  [a-zA-Z]*@*.*

Or for a more extensive test: isMatch($mail, ‘[a-z0-9!#$%&''*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&''*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?’)

Or try isMatch at mymendixdemo100-sandbox.mxapps.io

answered
2

The CommunityCommons module also contains the Rule EmailAddressRegex which you can use as a not too restrictive regex. 

answered
2

http://regexlib.com is my best friend in these situations

answered
0

Hi Norbert,

When checking e-mail addresses using regex I always like to keep it simple, as you need a very complex one to properly validate all valid e-mail addresss, which can get pretty complex. The following regex simply checks for the string to adhere to the following structure: (some text but no ‘@’) + @ + (some text but no ‘@’) + . + (some text but no ‘@’)

isMatch($YourObject/emailAddress, '^[^@]+@[^@]+\.[^@]+$')

 

If your question was not so much e-mail related but more regex related then just ignore my comment :)

EDIT: ah I didn’t notice your ‘Capital’ requirement, my bad

answered