Field validation question

0
How to ensure a field contains a certain character at all times as validation. can this be done using regular expression ?  an example will be helpful. basically this input field should not contain spaces , but should contain dot (.)
asked
1 answers
1

Yes can be done easily with regular expression
For example, 

^[A-Za-z.]*$

The above regex checks for any number of characters A-Z or a-z or a dot. Only combination of these characters will form a valid string. Spaces if added will make string invalid. You can further control amount of characters like one dots, 0 or more, at least one etc. 
 

one dot only [.]{1}
two dot only [.]{2}
zero or more [.]*
one or more  [.]+


In current regex, empty string is a valid string. You can modify * with + to have string with at least one character. 

Please follow some regex tutorial to understand the options available: https://docs.mendix.com/refguide/regular-expressions#1-introduction
https://medium.com/factory-mind/regex-tutorial-a-simple-cheatsheet-by-examples-649dc1c3f285

https://www.regular-expressions.info/tutorial.html

There are online editors available to test regex with strings. You can try those and when you create a regex matching your requirements you can use that. 



 

answered