Verification tools

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

In a development project, always verify only JS verification is not particularly insurance, here are some basic authentication method:

1 verification email

/// <summary>
        /// Verification email
        /// </summary>
        /// <param name="source">The target string</param>
        /// <returns>Validation results</returns>
         public static bool IsEmail(string source)
        {
            return Regex.IsMatch(source, @"^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([\.\-]?[a-zA-Z0-9]+)*)\.([A-Za-z]{2,})$", RegexOptions.IgnoreCase);
        }

2 verification.

       /// <summary>
        /// Verification.
        /// </summary>
        /// <param name="source">The target string</param>
        /// <returns>Validation results</returns>
              public static bool IsUrl(string source)
        {
            return Regex.IsMatch(source, @"^(((file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp)://)|(www\.))+(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(/[a-zA-Z0-9\&amp;%_\./-~-]*)?$", RegexOptions.IgnoreCase);
        }

3 verify whether containing URl

        /// <summary>
        /// Verify whether containing Url
        /// </summary>
        /// <param name="source">The target string</param>
        /// <returns>Validation results</returns>
              public static bool HasUrl(string source)
        {
            return Regex.IsMatch(source, @"(((file|gopher|news|nntp|telnet|http|ftp|https|ftps|sftp)://)|(www\.))+(([a-zA-Z0-9\._-]+\.[a-zA-Z]{2,6})|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(/[a-zA-Z0-9\&amp;%_\./-~-]*)?", RegexOptions.IgnoreCase);
        }

4 verification date

 public static bool IsDateTime(string source)
        {
            try
            {
                DateTime time = Convert.ToDateTime(source);
                return true;
            }
            catch
            {
                return false;
            }
        }

 5 verification of mobile phone No.

 public static bool IsMobile(string source)
        {
            return Regex.IsMatch(source, @"^0{0,1}(13[0-9]|14[0-9]|15[0-9]|18[0-9])[0-9]{8}$", RegexOptions.IgnoreCase);
        }

6 verification IP

  public static bool IsIPV4(string source)
        {
            return Regex.IsMatch(source, @"^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$", RegexOptions.IgnoreCase);
        }

7. Verification is it right? Normal character letters, numbers, or combination

 public static bool IsNormalChar(string source)
        {
            return Regex.IsMatch(source, @"[\w\d_]+", RegexOptions.IgnoreCase);
        }

8 Chinese

 public static bool IsChinese(string source)
        {
            return Regex.IsMatch(source, @"^[\u4e00-\u9fa5]+$", RegexOptions.IgnoreCase);
        }

Well there are some no validation will not write     why sticking out of the code so ugly  

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Dempsey at November 13, 2013 - 8:08 PM