Sometimes you need to verify whether an input string is composed of letters or numbers. An English word exactly interprets this requirement-alphanumeric. Sometimes you need to verify whether an input string is composed of letters or numbers. An English word exactly interprets this requirement-alphanumeric.
Further refine this requirement:
1. The string consists of at least one character (that is, the Null String is not passed)
2. uppercase/lowercase English letters and 0-9 digits are allowed (this is the main character)
3. Other characters, as long as they appear, cannot exceed, such as spaces and underscores.
For this question, regular expressions are just a single sentence, but what if regular expressions are not used?
It is also very simple. You can use ASCII codes to traverse strings one by one to determine.
Let's take a look at the ASCII code range:
1. digit characters 48-57
2. uppercase letters 65-90
3. lowercase letter 97-122
All the characters in these ranges are valid characters, so those out of the range must be invalid characters.
But don't forget the special case mentioned above-a null string.
Well, with these materials, we can easily write them out.
Function alphanumeric (string) {if (string. length <1) {return false ;}for (var I = 0; I
57 & code <65 | code> 90 & code <97 | code> 122) {return false ;}} return true ;}
The above is JavaScript fun: is a string composed of letters or numbers? For more information, see the PHP Chinese website (www.php1.cn )!