Saturday, August 11, 2018

Validation in Asp.net


Validation asp.net


password  validation  create secure  password -1



<asp:RegularExpressionValidator

         ID="Regex2" runat="server"

          ControlToValidate="TextBox3" 

  ValidationExpression="^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%*#?&])[A-Za-z\d$@$!%*#?&]{8,}$"   

           ErrorMessage="Invalid" ForeColor="Red" />



password  validation  create secure  password -2

<asp:RegularExpressionValidator

      ID="Regex2" runat="server"
                                                                               
       ControlToValidate="TextBox2" 
                                                                               
ValidationExpression="^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%*#?&_])[A-Za-z\d$@$!%*#?&_]{8,}$"   
                                                                               
        ErrorMessage="Invalid" ForeColor="Red" />




DOMAIN BASE MAIL VERIFICATION (@raisoni.net)
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"

runat="server" 

ControlToValidate="TextBox1"

ErrorMessage="Invalid Email" 

ValidationExpression="\w+([-+.]\w+)*"></asp:RegularExpressionValidator>
      


Without DOMAIN BASE MAIL VERIFICATION (@raisoni.net)
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"

runat="server" 

ControlToValidate="TextBox1"

ErrorMessage="Invalid Email" 

ValidationExpression="\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*">



MARKS  VALIDATION (Accept below 45)
<asp:RangeValidator ID="range1" runat="Server" ControlToValidate="TextBox3"

 Display="dynamic"

  ErrorMessage="*"

 MaximumValue="45"

  MinimumValue="0"
           
  Text="Only 0 to 45 ONLY NUMBER WILL BE ACCEPTED"
           
  Type="Integer"></asp:RangeValidator>


Paragraph Validation

protected void Button1_Click(object sender, EventArgs e)
    {

string[] words = TextBox4.Text.Split(new char[] { ' ' },

StringSplitOptions.RemoveEmptyEntries);


        if (words.Length > 200)
        {

            Response.write(“only accepted 200 word  “);

       
         }

         }




Spliting Date  Concept

System.Globalization.DateTimeFormatInfo mfi = new System.Globalization.DateTimeFormatInfo();

string strDate = TextBox5.Text; //Format – dd/MM/yyyy
//split string date by separator, here I'm using '/'

string[] arrDate = strDate.Split('/');

//now use array to get specific date object
string day = arrDate[0].ToString();
string month = arrDate[1].ToString();
string year = arrDate[2].ToString();
int mno = int.Parse(month);

Label3.Text  = mfi.GetMonthName(mno).ToString();
Label2.Text = day.ToString();
Label4.Text = year.ToString();

ACCEPT  only Number
<asp:RegularExpressionValidator ID="RegularExpressionValidator3"

runat="server"

ControlToValidate="TextBox6"

ErrorMessage="Only Number"           

ValidationExpression="(^([0-9]*|\d*\d{1}?\d*)$)">


</asp:RegularExpressionValidator>

Accept Only String
<asp:RegularExpressionValidator ID="RegularExpressionValidator4" runat="server"

ControlToValidate="TextBox7"

ErrorMessage="Do not  use special  symbol in a company name "

ValidationExpression="([A-Za-z])+( [A-Za-z]+)*"></asp:RegularExpressionValidator>

Mobile Number Validation
<asp:RegularExpressionValidator ID="RegularExpressionValidator5"

runat="server"

ControlToValidate="TextBox8"

ErrorMessage="Invalid mobile number"

ValidationExpression="\d{10}"></asp:RegularExpressionValidator>



No comments:

Post a Comment

GRIDVIEW ON ROW DATA BOUND EVENT

 Database Create  Student : roll , name , city , cost  Fix 6 Value  in Database Record  ====================================================...