I am using regex_search function to validate text in my reactive web application but it is returning false everytime. I want to validate that the text must have atleast one small letter, one capital letter, one number and one special character. The length of the text should be between 6-12, below is my regex pattern for this :
SyntaxEditor Code Snippet
^((?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[!@#$%^&*()_+?<>[\]{}=-])).{6,12}
Outsystem version: 11.7.9
Hi Nitin,
I have checked your pattern and its working
Find attached oml and use Sample Link For Regex
Regards
Rahul Sahu
Nitin Soni wrote:
Try this one:
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\da-zA-Z]).{6,12}$
you can test on this site or in your logic:https://regexr.com/
Best Regards
Carlos Lessa
Carlos Lessa wrote:
It is returning true for test@123, this string does not have capital letter
I should return false
funny on that website it works, I will try the same pattern in OS and check
I tried your pattern in the site I quote above and if you remove the first and last brackets and add a $ sign in the end, your pattern will start to work there, check your pattern with this additions
^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[!@#$%^&*()_+?<>[\]{}=-]).{6,12}$
Best regards
Find updated oml.
hope it will help you.
The regex pattern is working, the issue was in IgnoreCase property. IgnoreCase property was set to true.
I have set it to false and it is working now
Thanks
True, I didn't remember to tell you to check that, good luck with that
ps:. Follow the advice of Justin and Kilian
best regards
Hi,
If you are using the regex to validate a password it will check with sucess the following case:
test_@123 ae
Can you have a space in the middle of the Text var?
Always try to work around without the use of regular expressions.
Best Regards.
Hugo Dias wrote:
Hi Hugo, I'm not sure if you replied my post cuz I said to Trust the advice of 2 MVPs with years of experience but I think that I didn't say that your opinion isn't valid or right. I any case Wasnt the impression I tried to pass but the one to trust the 2 MVPs
But coming back to the regex code, the one in the post will accept the blank space but the right regex can validate if you have space on your string, check this pic bellow I use your example with a different regex code
and without space will pass
Regex can do a lot of validation if you use the right one.
Hi Carlos,
First of all, I was just focused on the problem and I was trying to add value to this subject. Nothing personal.I was just wondering if it is the case to validate a password it would probably not work as intended.
Note that a single RegEx is not really the best way to go here. Regular expressions can find a certain sequence very well, but testing for three occurences in random order in a string isn't really possible unless you use a pattern with all permutations (which quickly gets very unwieldly). Also, testing for the length is better done with Length().
Kilian Hekhuis wrote:
Agree 100% with Kilian. It also makes it much easier to debug, add more rules as-needed, and so on.
J.Ja
Like some already said you should avoid using regular expressions on your logic because they usually are difficult to maintain in the future. So take that into consideration if you chose to use them.
Anyway, for your problem I would suggest that first of all you use the Trim() on your Text Var and then check the length with the function Length().
Then you can use this regex pattern:
^(?=.*[\d])(?=.*[a-z])(?=.*[A-Z])(?=.*([^\w\s]|[_]))(\S+)$
Here are the results on regex101: https://regex101.com/r/okJibV/2
Finally, this is an example how you could implement the action in OutSystems
Cheers.