Ec (2); & nbsp; & lt ;? Php ** & nbsp; * PHP Regular Expression verification Class & nbsp; * CodebyT. t.R & nbsp; * [url] www.Gx3.cn [url] [url] Gx3.cn [url] & nbsp; * QQ: 252319874 & nbsp; * classregExp {& nbsp; & nbsp; stat script ec (2); script
/**
* PHP Regular Expression verification class
* Code by T.T. R
* [Url] http://www.Gx3.cn [/url] [url] http://Gx3.cn [/url]
* QQ: 252319874
*/
Class regExp
{
Static function strTrim ($ str)
{
Return preg_replace ("/s/", "", $ str );
}
Static function userName ($ str, $ type, $ len)
{
$ Str = self: strTrim ($ str );
If ($ len {
Return false;
} Else {
Switch ($ type)
{
Case "EN": // English only
If (preg_match ("/^ [a-zA-Z] + $/", $ str ))
{
Return true;
} Else {
Return false;
}
Break;
Case "ENNUM": // english number
If (preg_match ("/^ [a-zA-Z0-9] + $/", $ str ))
{
Return true;
} Else {
Return false;
}
Break;
Case "ALL": // allowed symbols (|-_ letter/number)
If (preg_match ("/^ [|-_ a-zA-Z0-9] + $/", $ str ))
{
Return true;
} Else {
Return false;
}
Break;
}
}
}
Static function passWord ($ min, $ max, $ str)
{
$ Str = self: strTrim ($ str );
If (strlen ($ str) >=$ min & strlen ($ str) <= $ max)
{
Return true;
} Else {
Return false;
}
}
Static function Email ($ str)
{
$ Str = self: strTrim ($ str );
If (preg_match ("/^ ([a-z0-9 _] | \-| \.) + @ ([a-z0-9 _] | \-) + \.) {1, 2} [a-z] {2, 4} $/I ", $ str ))
{
Return true;
} Else {
Return false;
}
}
Static function idCard ($ str)
{
$ Str = self: strTrim ($ str );
If (preg_match ("/^ ([0-9] {15} | [0-9] {17} [0-9a-z]) $/I", $ str ))
{
Return true;
} Else {
Return false;
}
}
Static function Phone ($ type, $ str)
{
$ Str = self: strTrim ($ str );
Switch ($ type)
{
Case "CHN ":
If (preg_match ("/^ ([0-9] {3} | 0 [0-9] {3})-[0-9] {7, 8} $ /", $ str ))
{
Return true;
} Else {
Return false;
}
Break;
Case "INT ":
If (preg_match ("/^ [0-9] {4}-([0-9] {3} | 0 [0-9] {3 }) -[0-9] {7,8 }$/", $ str ))
{
Return true;
} Else {
Return false;
}
Break;
}
}
}
$ Str = "008-010-2711204 ";
If (regExp: Phone ("INT", $ str ))
{
Echo "OK ";
} Else {
Echo "no ";
}
?>