Here is the regular of Lexrus:
The code is as follows |
Copy Code |
/^ ([a-z]+ (? =[0-9]) | [0-9]+ (? =[a-z])) [A-z0-9]+$/ig The idea is very clear AH: [A-z]+ (? =[0-9]) |
The beginning of the letter must be followed by a number.
[0-9]+ (? =[a-z]
The number begins with the letter followed.
[a-z0-9]+
The following characters can be used as long as they are numbers or letters. After testing, found that not working, 123DD will be recognized as illegal, dd123 is legitimate, visible "number at the beginning, immediately following the letter" is not functioning. The test code is as follows:
The code is as follows |
Copy Code |
<script type= "Text/javascript" > function IsTrue (str) { var reg=/^ ([a-z]+ (? =[0-9]) |[ 0-9]+ (? =[a-z])) [A-z0-9]+$/ig; return Reg.test (str); } var str? = ' AABC '; var str2 = ' aaa123 '; var str3 = ' 123dd '; var str4 = ' 1230923403982 '; document.write (IsTrue (str) + ' <br/> '); document.write (IsTrue (str2) + ' <br/> '); document.write (IsTrue (STR3) + ' <br/> '); document.write (IsTrue (STR4) + ' <br/> '); </script> |
The results are:
The code is as follows |
Copy Code |
False,true,false,false |
The third of the results, it is wrong to judge ' 123dd ' to be illegal. At first thought is the question of G, removed or not. Should be a browser bug, I think the Lexrus is correct, may be the browser can not handle or "|" Both sides of the is included forward check (? =).
The following revisions are followed:
/^ ([a-z]+[0-9]+) | ([0-9]+[a-z]+)] [a-z0-9]*$/i meaning is similar to above, but does not use forward check, the test code is as follows:
code is as follows |
copy code |
< Script type= "Text/javascript" > function istrue (str) { var reg=/^ ([a-z]+[0-9]+) | ( [0-9]+[a-z]+)] [a-z0-9]*$/i; return reg.test (str); } var str? = ' AABC '; var str2 = ' aaa123 '; var str3 = ' 123dd '; var str4 = ' 1230923403982 '; document.write (IsTrue (str) + ' <br/> '); document.write (IsTrue (str2) + ' <br/> '); document.write (IsTrue (STR3) + ' <br/> '); document.write (IsTrue (STR4) + ' <br/> '); </script> |
Result is
The code is as follows |
Copy Code |
False,true,true,false |
That's right.