This would be ok: 'AAAAAAA1222222' This would be not ok: '1AAAAA' This would not be ok: 'AA1AA'
Just looking for a way to check if a string is ALL letters and then ONLY letters afterward.
text.match(/^[A-Z]*\d*$/i)
Read this as "start of string followed by any number of letters followed by any number of digits followed by the end of the string."
Note this will match "", "A", and "1". If you want there to be at least one letter and at least one number, use + instead of * in both spots.
Use a lookahead. Lookaheads are used for validation, I suggest you go through this.
Try this out: ^(?=[A-Za-z]*\d*$).+
text.match(/^[a-zA-Z]+\d*$/);
Tests:
AAAAAAA1222222 - match
1AAAAA - no match
AA1AA - no match
AAAAAAA - match
2222222 - no match
If you dont want to match ALL Letters and at least one number change the quantifier of \d from +(1-infinite times) to *(0-infinity times)
more about regex quantifiers : link