Public classVerifyutil {/// <summary> ///the input string is judged to contain only Chinese characters/// </summary> /// <param name= "input" ></param> /// <returns></returns> Public Static BOOLIschinesech (stringinput) { returnRegex.IsMatch (Input,@"^[\u4e00-\u9fa5]+$"); } /// <summary> ///a phone number that matches the 3-bit or 4-bit area code, where the area code can be enclosed in parentheses .///You can also use a hyphen or a space between the area code and the local number .///You can also have no interval///\ (0\d{2}\) [-]?\d{8}|0\d{2}[-]?\d{8}|\ (0\d{3}\) [-]?\d{7}|0\d{3}[-]?\d{7}/// </summary> /// <param name= "input" ></param> /// <returns></returns> Public Static BOOLIsphone (stringinput) { stringPattern ="^\\ (0\\d{2}\\) [-]?\\d{8}$|^0\\d{2}[-]?\\d{8}$|^\\ (0\\d{3}\\) [-]?\\d{7}$|^0\\d{3}[-]?\\d{7}$"; returnRegex.IsMatch (Input,pattern); } /// <summary> ///determines whether the input string is a legitimate phone number/// </summary> /// <param name= "input" ></param> /// <returns></returns> Public Static BOOLIsmobilephone (stringinput) { returnRegex.IsMatch (Input,@"^1{3,5,8}\\d{9}$"); } /// <summary> ///the input string is judged to contain only numbers///can match integers and floating-point numbers///^-?\d+$|^ (-?\d+) (\.\d+)? $/// </summary> /// <param name= "input" ></param> /// <returns></returns> Public Static BOOLIsnumber (stringinput) { stringPattern =@"^-?\d+$|^ (-?\d+) (\.\d+)? $"; returnRegex.IsMatch (input, pattern); } /// <summary> ///determine if the input string is a valid email address/// </summary> /// <param name= "input" ></param> /// <returns></returns> Public Static BOOLIsemail (stringinput) { stringPattern =@"^ ([\w-\.] +) @ ((\[[0-9]{1,3}\. [0-9] {1,3}\. [0-9] {1,3}\.) | ([\w-]+\.) +)) ([a-za-z]{2,4}| [0-9] {1,3}) (\]?) $"; returnRegex.IsMatch (input, pattern); } /// <summary> ///determines whether the input string is a hyperlink/// </summary> /// <param name= "input" ></param> /// <returns></returns> Public Static BOOLIsurl (stringinput) { stringPattern =@"^[a-za-z]+://(\w+ (-\w+) *) (\. ( \w+ (-\w+) *) * (\?\s*)? $"; returnRegex.IsMatch (Input,pattern); } }
C # Regular Expression validation