Php Tutorial user registration filters Chinese user names. In many development scenarios, Chinese names are not allowed, so we create an example today to restrict Chinese name registration, in php, we can use regular expressions to restrict Chinese names such as preg_match ("/^ [". chr (0xa1 ). "-". chr (0xff ). "] + $/", let's look at the instance.
<? Php
Header ("Content-type: text/html; charset = gb2312 ");
Require_once ('Inc/connect. Php ');
$ Xm = isset ($ _ GET ['txt '])? $ _ GET ['txt ']: 'null ';
$ Ta = isset ($ _ GET ['tag'])? $ _ GET ['tag']: 3;
If ($ ta = 1 ){
If (preg_match ("/^ [". chr (0xa1). "-". chr (0xff). "] + $/", $ xm )){
Echo ("<div id = 'error'> Sorry, Chinese cannot be used as the user name! </Div> ");
Exit ();
}
If ($ xm = 'null' | $ xm = ''| strlen ($ xm)> 10 | strlen ($ xm) <3 ){
Echo ("<div id = 'error'> Sorry, the user is composed of 3-12aa_zz and numbers! </Div> ");
Exit ();
} Else {
$ Result = mysql tutorial _ query ("select m_uid from wk_member where m_uid = '$ xm'") or die ('error! '. Mysql_error ());
If (! Mysql_num_rows ($ result )){
Echo ("<div id = 'success'> <font color = red> & nbsp; congratulations! This user can register! </Font> </div> ");
} Else {
Echo ("<div id = 'error'> Sorry, the user has been registered. Please select another name! </Div> ");
}
}
} Elseif ($ ta = 0 ){
If (@ file_get_contents ($ xm )){
Echo '<div id = "success"> & nbsp; blog address accessible </div> ';
} Else {
Echo '<div id = "error"> Sorry, the blog address you entered cannot be accessed normally <div> ';
}
} Else {
Echo "<div id = 'error'> Sorry, the operation is invalid! </Div> ";
}
?>
Summary:
The method is very simple. You only need to obtain the user input and use preg_match to judge.