Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
189
rated 0 times [  194] [ 5]  / answers: 1 / hits: 38855  / 14 Years ago, tue, march 8, 2011, 12:00:00

What is the easiest way to check if an expression has English or number characters only? with no spaces and no other characters.



p.s - the first character cannot be a number. upper or lower case.


More From » regex

 Answers
5

I would use: /^[A-Za-z][A-Za-z0-9]*$/. Here are same examples:



/^[A-Za-z][A-Za-z0-9]*$/.test(expression);
/^[A-Za-z][A-Za-z0-9]*$/.test(EXPRESSION);
/^[A-Za-z][A-Za-z0-9]*$/.test(e123xpression);
/^[A-Za-z][A-Za-z0-9]*$/.test(E123xpression);
/^[A-Za-z][A-Za-z0-9]*$/.test(1expression);


Without boundaries (^ and $) regexp match any substring too.



EDIT: Updated invalid expression


[#93381] Sunday, March 6, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
elaine

Total Points: 628
Total Questions: 111
Total Answers: 104

Location: Marshall Islands
Member since Tue, Sep 21, 2021
3 Years ago
;