C # RegEx. ismatch (Regular Expression verification: Number, decimal point, mail, and computation expression)

Source: Internet
Author: User

Specific use can refer to: http://blog.csdn.net/tsinfeng/archive/2010/07/16/5739366.aspx

Public bool isint (string Str)
{
// ^ ([+-]?) Indicates that the addition/subtraction sign can only appear at the beginning of a string and has only one
/// D * indicates that there can be multiple or one decimal number.
// $ Indicates the end of the string
Return RegEx. ismatch (STR, @ "^ ([+-]?) /D * $ "); // returns an integer that can only begin with a positive or negative number.
}
Public bool isunint (string Str)
{
// ^ ([+-]?) Indicates that the addition/subtraction sign can only appear at the beginning of a string and has only one
/// D * indicates that there can be multiple or one decimal number.
// $ Indicates the end of the string
Return RegEx. ismatch (STR, @ "^/D * $"); // returns an integer.
}
Public bool isemail (string Str)
{
// The Mail format is string @ string. String (the last string must be 1 to 3 characters)
Return RegEx. ismatch (STR, @ "^ ([/W] *) ([@]?) ([/W] *) ([.]?) ([/W] {1, 3}) $ ");
}
Public bool checkfloat (string svalue)
{
// Check whether the value is a floating point number with 5 decimal places
Return RegEx. ismatch (svalue, @ "^ (/D *) ([.] {0, 1}) (/d {0, 5}) $ ");
}
Public bool isnumeric (string Str)
{
// Determines whether it is a numeric value with a decimal point
Return RegEx. ismatch (STR, @ "^ ([+-]?) /D * [.]? /D * $ ");
}
Public bool isvalidemail (string strin)
{
// Return true if strin is in valid e-mail format.
Return RegEx. ismatch (strin,
@ "^ ([/W-/.] +) @ (/[0-9] {1, 3 }/. [0-9] {1, 3 }/. [0-9] {1, 3 }/.) | ([/W-] + /.) +) ([A-Za-Z] {2, 4} | [0-9] {1, 3}) (/]?) $ ");
}

Public static bool checkstring (string svalue)
{
If (RegEx. ismatch (svalue, @ "^ ([0-9] {1 ,})(. *) ([0-9] {1,}) $ "))
{
// If the expression starts with a number
// Check whether the matching operator is addition, subtraction, multiplication, and division. If not, the return result is true.
If (RegEx. ismatch (svalue,
@ "([0-9] {1,}) ([/+/-/*/] {2 ,}) ([0-9] {1,}) | ([0-9] {1 ,}) ([^/+/-/* //] {1,}) ([0-9] {1 ,}))"))
{
// The expression is invalid.
Return false;
}
Else
{
Return true;
}
}
Else
{
Return false;
}
}

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.