The Application of dot net regular expressions is also indispensable in dot net development.
Public class regularfun
{
Public regularfun ()
{
}
/// <Summary>
/// Determine whether a number is an integer
/// </Summary>
/// <Param name = "strnumber"> string </param>
/// <Returns> </returns>
Public static bool isinteger (string strnumber)
{
RegEx objnotintpattern = new RegEx ("[^ 0-]");
RegEx objintpattern = new RegEx ("^-[0-9] + $ | ^ [0-9] + $ ");
Return! Objnotintpattern. ismatch (strnumber )&&
Objintpattern. ismatch (strnumber );
}
/// <Summary>
/// Determine whether only characters and numbers are composed.
/// </Summary>
/// <Param name = "strtocheck"> </param>
/// <Returns> </returns>
Public static bool isalphanumeric (string strtocheck)
{
RegEx objalphanumericpattern = new RegEx ("[^ a-zA-Z0-9]");
Return! Objalphanumericpattern. ismatch (strtocheck );
}
/// <Summary>
/// Check Logon Name: You can enter only 5-20 strings starting with a letter, which can contain numbers, "_", and ".".
/// </Summary>
/// <Param name = "username"> </param>
/// <Returns> </returns>
Public static bool isregusername (string username)
{
RegEx objalphanumericpattern = new RegEx ("^ [A-Za-Z] {1} ([a-zA-Z0-9] | [. _]) {} $ ");
Return! Objalphanumericpattern. ismatch (username );
}
/// <Summary>
/// Password verification: only 6-20 letters, numbers, and underscores can be entered
/// </Summary>
/// <Param name = "password"> </param>
/// <Returns> </returns>
Public static bool ispassword (string password)
{
RegEx objalphanumericpattern = new RegEx (@ "^ (\ W) {6, 20} $ ");
Return! Objalphanumericpattern. ismatch (password );
}
/// <Summary>
/// Check the common phone number and fax number. It can start with "+" and contain "-" in addition to numbers.
/// </Summary>
/// <Param name = "tel"> </param>
/// <Returns> </returns>
Public static bool istelepone (string Tel)
{
RegEx objalphanumericpattern = new RegEx (@ "^ [+] {0, 1} (\ D) {1, 3} []? ([-]? (\ D) | []) {1, 12}) + $ ");
Return! Objalphanumericpattern. ismatch (TEL );
}
/// <Summary>
/// Verify the mobile phone number: it must start with a number and can contain "-" in addition to a number.
/// </Summary>
/// <Param name = "mobile"> </param>
/// <Returns> </returns>
Public static bool ismobil (string mobile)
{
RegEx objalphanumericpattern = new RegEx (@ "^ [+] {0, 1} (\ D) {1, 3} []? ([-]? (\ D) | []) {1, 12}) + $ ");
Return! Objalphanumericpattern. ismatch (mobile );
}
/// <Summary>
/// Check the IP address
/// </Summary>
/// <Param name = "ipaddr"> </param>
/// <Returns> </returns>
Public static bool isipaddress (string ipaddr)
{
RegEx objalphanumericpattern = new RegEx (@ "^ [0-9.] {1, 20} $ ");
Return! Objalphanumericpattern. ismatch (ipaddr );
}
}