Common regular expression function class (C # version)

xiaoxiao2021-03-06  15

DOT NET regular expression app, is also indispensable in DOT NET development

Public class regularfun {

Public regularfun () {}

///

/// judge whether a number is integer /// /// string /// public static Bool isinteger (String StrnotintPattern = new regex ("[^ 0-9-]"); regex objintpattern = new regex ("^ - [0-9] $ | ^ [0-9] $" ); Return! ObjNotintPattern.ismatch (strnumber) &&bjintpattern.ismatch (strnumber);}

///

/// determines if only characters and numbers are composed /// /// /// public static Bool isalphanumeric (string stralphanumericpattern = new regex ("[^ a-za-z0-9]"); return! objalphanumericPattern.ismatch (strtocheck);} /// /// verify login name : You can only enter 5-20 strings that start with letters, numbers, "_", "." //// /// // / public static bool isregusername (string username) {regex objalphanumericPattern = new regex ("^ [a-za-z] {1} ([A-ZA-Z0-9] | [._] {4,19} $ "); return! ObjalphanumericPattern.ismatch (username);} /// /// check password: You can only enter 6-20 letters, numbers, underscores /// /// /// public static bool ispassword (string password) {regex objalphanumericPattern = new regex (@ "^ (/ w) { 6, 20} $ "); return! ObjalphanumericPattern.ismatch (password);}

///

/// Check ordinary phone, fax number: " " start, in addition to the digital, "-" /// /// /// public static bool istelepone (string tel) {regex objalphanumericPattern = new regex (@ "^ [ ] {0,1} (/ d) {1,3} [ ]? ([-]? ((/ d) | []) {1, 12}) $ "); return! objalphanumericPattern.ismatch (tel);} /// /// check mobile number : Must start with the beginning, in addition to the numbers, can contain "-" /// /// /// public static bool Ismobil (String Mobile) {regex objalphanumericPattern = new regex (@ "^ [ ] {0,1} (/ d) {1,3} []? ([-]? (/ D) | []) { 1, 12}) $ "); return! ObjalphanumericPattern.ismatch (mobile);

///

/// Verify IP address /// /// /// public static bool isipaddress String ipaddr) {regex objalphanumericPattern = new regex (@ "^ [0-9.] {1, 20} $"); return! objalphanumericPattern.ismatch (ipaddr);}

}

转载请注明原文地址:https://www.9cbs.com/read-48036.html

New Post(0)