Friday, 11 January 2013

validation

40280914/05/930   mayur 420------bhushan 929
d133028
b131816
sainathom
SelectedValue=
-------------------------------------------------------------------------------
gaurav rnd date funtion

DateTime.Parse(strinput);
            string[] arr = strinput.Split('/');
            string strNewDate = arr[1] + "/" + arr[0] + "/" + arr[2];

            string strRegex = @"^(?:(?:31(\/|-|\.)(?:0?[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0?[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)0?2\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0?[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0?[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{2})$"; // dd/mm/yyyy
            //@"^([0]\d|[1][0-2])\/([0-2]\d|[3][0-1])\/([2][01]|[1][6-9])\d{2}(\s([0-1]\d|[2][0-3])(\:[0-5]\d){1,2})?$"; // MM/dd/yyyy

            Regex re = new Regex(strRegex);

            if (re.IsMatch(strNewDate))
                return (true);
            else
                return (false);
------------------------------------------------------------------------------
[0-9a-zA-Z :]*
.+.(P|p)(D|d)(F|f)$        for pdf file
[^<>]{5,8000}
regular expression allowing alphabets and spaces only

 1 Numbers only regular expression (0-9 regex) – ^[0-9]*$
 2 Decimal numbers with 2 floating point compulsory regular expression (0-9 with decimal) – ^([0-9]*)(\.[0-9]{2})?$
 3 Alphabets only regular expression () – ^[a-zA-Z]*$
 4 Alphanumeric string regular expression – ^[a-zA-Z0-9]*$
 5 Alphanumeric and white space regular expression – ^[a-zA-Z0-9 ]*$

([0-0]{1}[1-9]{1}[0-9]{9})|[1-9]{1}[0-9]{9}  mobile 10 or 11
(?([1-9]{1})?([0]{1}[1-9]{1})?([0-9]{9})   for javascript
 setfocusonerror="true" 

^[!@#$%*()/_+=^&amp;{}|\[\]:;&amp;quot;?.,\'\s`\-~a-zA-z0-9]{2,300}$         commnet  -----------no reload-------------------
   <script type="text/javascript" language="javascript" >

        window.history.forward();

        function noBack() {

            window.history.forward();

        }

    </script>
  
    </head>
    <body onload="noBack();" onpageshow="if(event.persisted) noBack();" onunload="">
-----------------------------------c sharp------
 static bool IsValid(string value)
    {
    return Regex.IsMatch(value, @"^[a-zA-Z0-9]*$");
    }


Regex regex = new Regex(@"\d+");
    Match match = regex.Match("Dot 55 Perls");
    if (match.Success)
    {
        Console.WriteLine(match.Value);
    }
Regex a1 = new Regex(@"^\s+", RegexOptions.Compiled);
Regex a2 = new Regex(@"\s+$", RegexOptions.Compiled);

foreach (object item in _collection) // Example loop.
{
    //
    // Reuse the compiled regex objects over and over again.
    //
    string source = "  Some text ";
    source = a1.Replace(source, "");
    source = a2.Replace(source, ""); // compiled: 3620
}
-----------------------------------------
const string example = @"This string
has two lines";

    // Get a collection of matches with the Multiline option.
    MatchCollection matches = Regex.Matches(example, "^(.+)$", RegexOptions.Multiline);
    Regex regex = new Regex("dotnet.*");
    Console.WriteLine(regex.IsMatch("dotnetperls")); // True
    //
    // Zero or more s letters are allowed.
    //
    regex = new Regex("perls*");
    Console.WriteLine(regex.IsMatch("perl")); // True
    Console.WriteLine(regex.IsMatch("perlssss")); // True
    Console.WriteLine(regex.IsMatch("pert")); // False
    //
    // Use the star with a parentheses grouping.
    // ... Also use the $ sign to signal the terminal.
    //
    regex = new Regex("sam(abc)*$");
    Console.WriteLine(regex.IsMatch("samabcabc")); // True
    Console.WriteLine(regex.IsMatch("sam")); // True
    Console.WriteLine(regex.IsMatch("samab")); // False
-----------------------------------------
static string CollapseSpaces(string value)
    {
    return Regex.Replace(value, @"\s+", " ");
    }

    static void Main()
    {
    string value = "Dot  Net  Perls";
    Console.WriteLine(CollapseSpaces(value));
    value = "Dot  Net\r\nPerls";
    Console.WriteLine(CollapseSpaces(value));
    }

-----------------------------------------
static void Main()
    {
    // 1
    // The string you want to change.
    string s1 = "This string has something at the end<br/>";

    // 2
    // Use regular expression to trim the ending string.
    string s2 = System.Text.RegularExpressions.Regex.Replace(s1, "<br/>$", "");

    // 3
    // Display the results.
    Console.WriteLine("\"{0}\"\n\"{1}\"",
        s1,
        s2);


const string input = "There are 4 numbers in this string: 40, 30, and 10.";
    // Split on one or more non-digit characters.
    string[] numbers = Regex.Split(input, @"\D+");
    foreach (string value in numbers)
    {
        if (!string.IsNullOrEmpty(value))
        {
        int i = int.Parse(value);
        Console.WriteLine("Number: {0}", i);
        }
    }




    }
his string has something at the end
-----------------------------------------

using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main()
    {
    // Input strings.
    const string s1 = "samuel allen";
    const string s2 = "dot net perls";
    const string s3 = "Mother teresa";

    // Write output strings.
    Console.WriteLine(TextTools.UpperFirst(s1));
    Console.WriteLine(TextTools.UpperFirst(s2));
    Console.WriteLine(TextTools.UpperFirst(s3));
    }
}

public static class TextTools
{
    /// <summary>
    /// Uppercase first letters of all words in the string.
    /// </summary>
    public static string UpperFirst(string s)
    {
    return Regex.Replace(s, @"\b[a-z]\w+", delegate(Match match)
    {
        string v = match.ToString();
        return char.ToUpper(v[0]) + v.Substring(1);
    });
    }
}

Output

Samuel Allen
Dot Net Perls
Mother Teresa

-------------------------------------------

public int PageNumber
    {
        get
        {
            if (ViewState["PageNumber"] != null)
                return Convert.ToInt32(ViewState["PageNumber"]);
            else
                return 0;
        }
        set
        {
            ViewState["PageNumber"] = value;

        }
    }

  var filter2 =/^\(?([6-9]{2})?([6-9]{1})?([0-9]{10})$/

    if (document.getElementById("txtmobileno").value!= "")
    {

                if (filter2.test(document.getElementById("txtmobileno").value))
            {
               
            }
            else
            {
                inlineMsg('txtmobileno','The Mobile No. length should be  10 or 12 characters.',7);
                document.getElementById("txtmobileno").value="";
                document.getElementById("txtmobileno").focus();
                return false;
             }
   
    }

  var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;       
            if(reg.test(document.getElementById("txtname").value) == false)
            {        
               inlineMsg('txtname','Please enter a valid email id. You will login to your account using this ID.',7);
             document.getElementById("txtname").focus();
              return false;
            }




function ValidateCheckBox(sender, args) {
            if (document.getElementById("<%=chkTerms.ClientID %>").checked == true) {
                args.IsValid = true;
            } else {
                args.IsValid = false;
            }
        }
<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="Required Terms and Conditions"
                                ClientValidationFunction="ValidateCheckBox"></asp:CustomValidator>





  function ValidateFile(sender, args)
     {
   
            if (document.getElementById("<%=fileREsume.ClientID%>").value == "")
         {
                args.IsValid = true;
         }
         else
          {
           
                 var file = document.getElementById('<%=fileREsume.ClientID %>');
                var len=file.value.length;
                var ext=file.value;
          
               if(len > 3)
               
                 {
              
                     if((ext.substr(len-3,len)=="doc")||(ext.substr(len-3,len)=="DOC"))
                    {
                      args.IsValid = true;
                    } else
                     if((ext.substr(len-3,len)=="rtf")||(ext.substr(len-3,len)=="RTF"))
                    {
                      args.IsValid = true;
                    } else
                     if((ext.substr(len-3,len)=="ocx")||(ext.substr(len-3,len)=="OCX"))
                    {
                      args.IsValid = true;
                    }
                     else
                     {
                     args.IsValid = false;
                    }
                }
          
              
            }
        }

No comments:

Post a Comment