In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces which verification operations are commonly used in .net projects, which are very detailed and have certain reference value. Friends who are interested must finish reading them.
In the project, the information input by users and the results generated by some methods need to be verified. Generally, js plug-ins or js are often used to verify the relevant information in the project, but from the point of view of project security, js injection can be carried out on the system.
If it is relatively safe to verify the information entered by the user in the background, when the information verification is illegal, you can directly throw an exception in the program and terminate the operation of the program.
Several more common verification methods are now available to reduce development time and errors in the project:
1. Determine the domain name:
/ ordinary domain name / public static bool IsCommonDomain (string value) {return QuickValidate ("^ (www.)? (\\ w+\\.) {1Yue3} (org | org.cn | gov.cn | com | cn | net | cc) $", value.ToLower ();}
two。 Check whether a string is made up of pure numbers, which is generally used to verify the validity of query string parameters:
/ check whether a string is made up of pure numbers, which is generally used to verify the validity of query string parameters. / / string to be verified. / / whether the Bool value is legal. Public static bool IsNumeric (string value) {return QuickValidate ("^ [-]? [1-9] * [0-9] * $", value);}
3. Check whether a string is made up of pure letters and numbers, which is generally used to query the validity of string parameters:
/ check whether a string is made up of pure letters and numbers, which is generally used to verify the validity of query string parameters. / / string to be verified. / / whether the Bool value is legal. Public static bool IsLetterOrNumber (string value) {return QuickValidate ("^ [a-zA-Z0-9 _] * $", value);}
4. To determine whether it is a number, including decimals and integers:
Determine whether it is a number, including decimals and integers. / / string to be verified. / / whether the Bool value is legal. Public static bool IsNumber (string value) {return QuickValidate ("^ (0 | ([1-9] + [0-9] *)) (. [0-9] +)? $", value);}
5. Quickly verify that a string conforms to the specified regular expression:
/ / quickly validates whether a string matches the specified regular expression. / / the contents of the regular expression. / / the string to be verified. / / whether the Bool value is legal. Public static bool QuickValidate (string express, string value) {var myRegex = new System.Text.RegularExpressions.Regex (express); return value.Length! = 0 & myRegex.IsMatch (value);}
6. Determine whether a string is a message:
/ public static bool IsEmail (string value) {var regex = new System.Text.RegularExpressions.Regex (@ "^\ w+ ([- +.]\ w+) * @ (\ w+ ([-.]\ w+) *\.) + ([a-zA-Z] +) + $", RegexOptions.IgnoreCase); return regex.Match (value) .success;}
7. Determine whether a string is a zip code:
/ determine whether a string is zip code / public static bool IsZipCode (string value) {return QuickValidate ("^ ([0-9] {6}) $", value);}
8. Determine whether a string is in ID format:
/ determine whether a string is in ID format / public static bool IsIdCard (string value) {System.Text.RegularExpressions.Regex regex; string [] strArray; if ((value.Length! = 15) & & (value.Length! = 0x12)) {return false } if (value.Length = = 15) {regex = new System.Text.RegularExpressions.Regex (@ "^ (\ d {6}) (\ d {2}) (\ d {3}) $"); if (! regex.Match (value) .success) {return false;} strArray = regex.Split (value) Try {var dateTime = new DateTime (int.Parse ("19" + strArray [2]), int.Parse (strArray [3]), int.Parse (strArray [4]); return true;} catch {return false;}} regex = new System.Text.RegularExpressions.Regex (@ "^ (\ d {6}) (\ d {4}) (\ d {2}) (\ d {2}) (\ d {3}) ([0-9Xx]) $") If (! regex.Match (value) .success) {return false;} strArray = regex.Split (value); try {var dateTime = new DateTime (int.Parse (strArray [2]), int.Parse (strArray [3]), int.Parse (strArray [4])); return true;} catch {return false;}}
9. Judge whether it is pure Chinese or not:
/ public static bool IsChinese (string value) {var regex = new System.Text.RegularExpressions.Regex (@ "^ [\ u4E00 -\ u9FA5\ uF900-\ uFA2D] + $", RegexOptions.IgnoreCase); return regex.Match (value) .success;}
10. Determine whether a string is a mobile phone number:
/ determine whether a string is a mobile phone number / public static bool IsMobileNum (string value) {var regex = new System.Text.RegularExpressions.Regex (@ "^ (13 | 15)\ d {9} $", RegexOptions.IgnoreCase); return regex.Match (value) .success;}
11. Determine whether a string is a phone number:
/ determine whether a string is a phone number / public static bool IsPhoneNum (string value) {var regex = new System.Text.RegularExpressions.Regex (@ "^ (86)? (-)? (0\ d {2pm 3})? (-)? (\ d {7pr 8}) (-)? (\ d {3pm 5})? $", RegexOptions.IgnoreCase); return regex.Match (value) .success;}
twelve。 Determine whether a string is a URL:
/ determine whether a string is the URL / public static bool IsUrl (string value) {var regex = new System.Text.RegularExpressions.Regex (@ "(http://)?([\w-]+\.)*[\w-]+(/[\w-. /?% & =] *)?, RegexOptions.IgnoreCase); return regex.Match (value) .success;}
13. Determine whether a string is an IP address:
/ determine whether a string is an IP address / public static bool IsIp (string value) {var regex = new System.Text.RegularExpressions.Regex (@ "^ ((2 [0-4] {1} [0-9] {1}) | (25 [0-5] {1})) | (1 [0-9] {2}) | ([1-9] {1} [0-9) ] {1}) | ([0-9] {1})). (2 [0-4] {1} [0-9] {1}) | (25 [0-5] {1})) | (1 [0-9] {2}) | ([1-9] {1}] {1}). ((2 [0-4] {1} [0-9] {1}) | (25) [0-5] {1})) | (1 [0-9] {2}) | ([1-9] {1}) | ([0-9] {1})). ((2 [0-4] {1} [0-9] {1}) | (25 [0-5] {1})) | (1 [0-9] {2}) | ([1-9] {1} [0-9] {1}) | ([0-9] {1})) $" RegexOptions.IgnoreCase) Return regex.Match (value) .success;}
14. Determine whether a string is alphanumeric:
/ determine whether a string is alphanumeric ("[a-zA-Z0-9]?" / public static bool IsWordAndNum (string value) {var regex = new System.Text.RegularExpressions.Regex ("[a-zA-Z0-9]?"); return regex.Match (value) .Success } these are all the contents of the article "what are the common validation operations in .net projects?" Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un