TextBox can only enter numbers or Chinese common regular expressions and validation methods

Source: Internet
Author: User

Regular expression set for validating numbers
Verification Number: ^[0-9]*$
To verify N-bit numbers: ^\d{n}$
Verify that at least n digits: ^\d{n,}$
Verify the number of m-n bits: ^\d{m,n}$
Verify numbers starting with 0 and non 0: ^ (0|[ 1-9][0-9]*) $
Verify that there is a positive real number with two decimal places: ^[0-9]+ (. [ 0-9]{2})? $
Verify that there is a positive real number with 1-3 decimal places: ^[0-9]+ (. [ 0-9]{1,3})? $
Verify non-zero positive integers: ^\+? [1-9] [0-9]*$
To verify a nonzero negative integer: ^\-[1-9][0-9]*$
Validating non-negative integers (positive integers + 0): ^\d+$
Validates a non-positive integer (negative integer + 0): ^ ((-\d+) | ( 0+)) $

Validation of Chinese regular expression collection
Verify all Olympics languages: ^[\?-\? +$
Verify simplified and traditional: ^[\ a-\?] +$
Verified Simplified: ^[\-\ calls]+$

Use the following method

Bs

var reg =/^ (\d{1,4}) (-|\/) (\d{1,2}) \2 (\d{1,2}) $/;
var r = Str.match (reg);
if (r==null)

Alert (' Validation failed! ');

Or

if (!reg.test (str))

Alert (' Validation failed! ');

Cs

Using a Regex object to first reference System.Text.RegularExpressions
String s= "^[0-9]*$";//Regular expression
Regex reg=new Regex (s);
if (!reg. IsMatch (This.textbox1.text))
{
MessageBox.Show ("Please enter a number");
}

TextBox can only enter numbers or Chinese common regular expressions and validation methods

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.