Regex help!

3
I need a couple of Regex expressions for the following cases, I hope someone can give me a hand! Alphabetical characters only. Max of 5 characters allowed Alphabetical characters only. Max of 30 characters allowed Alphabetical characters only. Max of 30 characters allowed Numerical values only.Has to be 10 characters excluding spaces. Numerical values only. Has to be 4 characters excluding spaces. Thanks!
asked
2 answers
4

See Wikipedia and Mendix documentationfor help on regular expressions.

But ill try to help you a bit, please bear in mind that the first 3 are only alphabetical characters and do not include numbers.

  1. [a-zA-Z]{0,5}
  2. [a-zA-Z]{0,30}
  3. see 2
  4. [0-9 \t]{9}
  5. [0-9 \t]{4}

I think that should do the trick.

answered
1

In addition to Pieters answer, in general you want to make sure that there is nothing else in the string, so start with ^ and end with $ (those match string start and string end). for example:

^[0-9]{9}$

or

^\s*[0-9]{9}\s*$

if the number is allowed to be surrounded with whitespace.

answered