Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
174
rated 0 times [  180] [ 6]  / answers: 1 / hits: 27222  / 13 Years ago, tue, august 16, 2011, 12:00:00

It doesn't matter how many letters and digits, but string should contain both.



Jquery function $('#sample1').alphanumeric() will validate given string is alphanumeric or not. I, however, want to validate that it contains both.


More From » javascript

 Answers
920

So you want to check two conditions. While you could use one complicated regular expression, it's better to use two of them:



if (/d/.test(string) && /[a-zA-Z]/.test(string)) {


This makes your program more readable and may even perform slightly better (not sure about that though).


[#90591] Sunday, August 14, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
louiemarvinm

Total Points: 473
Total Questions: 103
Total Answers: 94

Location: Samoa
Member since Mon, Nov 8, 2021
3 Years ago
;