Simple C # Validation class

Source: Internet
Author: User
Tags date bool
Using System;
Using System.Text.RegularExpressions;
Namespace Bobomousecom.crm
{
<summary>
Summary description of the regexlib.
</summary>
public class Regexlib
{
Public Regexlib ()
{
//
TODO: Add constructor logic here
//
}

Search the input string and return all href= "..." values
String Dumphrefs (String inputstring)
{
Regex R;
Match m;
R = new Regex ("href\\s*=\\s*: \" (? <1>[^\ "]*") | (? <1>\\s+)) ",
regexoptions.ignorecase|regexoptions.compiled);
for (M = R.match (inputstring); m.success m = M.nextmatch ())
{
Return ("Found href" + m.groups[1]);
}
}

Verify email address
BOOL IsValidEmail (String strin)
{
Return true if Strin are 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}) (\]?) $");
}

The Dd-mm-yy date form replaces the Mm/dd/yy date form.
String mdytodmy (String input)
{
return Regex.Replace (Input, "\\b (? \\d{1,2})/(? \\d{1,2})/(? \\d{2,4}) \\b", "${day}-${month}-${year}");
}

Verify that you are a decimal
BOOL Isvaliddecimal (String strin)
{

return Regex.IsMatch (strin,@ "[0].\d{1,2}|[ 1] ");
}

Verify that you are a phone number
BOOL Isvalidtel (String strin)
{
return Regex.IsMatch (strin,@) (\d+-)? ( \d{4}-?\d{7}|\d{3}-?\d{8}|^\d{7,8}) (-\d+)? ");
}

Date verified
BOOL Isvaliddate (String strin)
{
return Regex.IsMatch (strin,@ "^2\d{3}-" (?: 0?) [1-9]|1[0-2])-(?: 0? [1-9]| [1-2]\d|3[0-1]) (?: 0? [1-9]|1\d|2[0-3]):(?: 0? [1-9]| [1-5]\d):(?: 0? [1-9]| [1-5]\d) $ ");
}

Verify suffix Name
BOOL Isvalidpostfix (String strin)
{
return Regex.IsMatch (strin,@ "\. i:gif|jpg) $ ");
}

Verify that the characters are between 4 and 12
BOOL Isvalidbyte (String strin)
{
return Regex.IsMatch (strin,@ "^[a-z]{4,12}$");
}

Verifying IP
BOOL Isvalidip (String strin)
{
return Regex.IsMatch (strin,@ "^ (\d{1,2}|1\d\d|2[0-4]\d|25[0-5]) \. ( \D{1,2}|1\D\D|2[0-4]\D|25[0-5]) \. (\d{1,2}|1\d\d|2[0-4]\d|25[0-5]) \. (\d{1,2}|1\d\d|2[0-4]\d|25[0-5]) $ ");
}
}
}

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.