Any characters 6 to 16 are. {6, 16}
Only numbers, letters, and underscores are composed of [0-9_a-zA-Z]
Add the total to pepper ^ [_ 0-9a-z] {6, 16} $
The code is as follows: |
Copy code |
<? Php Function ispassword ($ str ){ If (preg_match ('/^ [_ 0-9a-z] {6, 16} $/I', $ str )){ Return true; } Else { Return false; } } $ Password = 'abcde @'; If (ispassword ($ password )){ Echo 'conformances '; } Else { Echo 'nonconformity '; } // Output does not match Echo '<br> '; $ Password = 'abcdeasdas _ 000000 '; If (ispassword ($ password )){ Echo 'conformances '; } Else { Echo 'nonconformity '; } // Output ?> |
Example 2
The code is as follows: |
Copy code |
$ Action = trim ($ _ get ['action']); If ($ action = "sub ") { $ Str = $ _ post ['dir']; // If (! Preg_match ("/^ [". chr (0xa1 ). "-". chr (0xff ). "A-Za-z0-9 _] + $/", $ str) // gb2312 regular expression of Chinese characters, letters, numbers, underscores (_) If (! Preg_match ("/^ [x {4e00}-x {9fa5} A-Za-z0-9 _] + $/u", $ str) // regular expression of UTF-8 Chinese characters, letters, numbers, underscores (_) { Echo "<font color = red> the [". $ str. "] you entered contains illegal characters </font> "; } Else { Echo "<font color = green> the [". $ str. "] you entered is completely legal. Pass! </Font> "; } } ?> <Form method = "post" action = ""> Input characters (numbers, letters, Chinese characters, and underlines ): <Input type = "text" name = "dir" value = ""> <Input type = "submit" value = "submit"> </Form>
|