Regular Expression Rule analysis:
. { 7}: The entire string length is greater than 6, note: here. Match any character
^s*$: The entire string is empty or is a white space character
The author uses the order of the regular expression to negate the look, indicates that there can be no more than 7 characters after the start (^), or that the entire string is empty (if S is not, ^$ represents empty), or all whitespace characters (s*).
However, the regular expression can remove the ^ from the look in the condition, that is, the/^ (?!. {7}|s*$)/g, because the rules were already in the beginning of a ^.
code is as follows |
copy code |
<script Type= "Text/javascript" > /** * has at least one non-white-space character and no more than 6-character regular expression * / var pattern =/^ (?!. {7}|s*$)/g; var str = ""; var str1 = ""; var str2 = "a"; var str3 = www.111cn.net; var str4 = "a"; document.write (Pattern.test (str)) document.write (Pattern.test (str1)) document.write (Pattern.test ( STR2)) document.write (Pattern.test (STR3)) document.write (Pattern.test (STR4)) </script> |