Click here to Skip to main content
15,889,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to give the validation using javascript in asp.net for Mobno and Email



<script type="text/javascript">
function validate() {
var cno, email,Msg;

cno = document.getElementById("txt_Cno").value;
email = document.getElementById("txt_EmailID").value;

if (cno == "") {
Msg = Please Enter only No \n;
}
if (email == ) {
Msg +=Please valid Email \n;
}

return alert(Msg);




}
</script>
Posted

1 solution

try this
C#
<script type="text/javascript">
function validate()
{
  if( document.mobilenumbervalidation.mobileno.value == "" ||
           isNaN( document.mobilenumbervalidation.mobileno.value) ||
           document.mobilenumbervalidation.mobileno.value.length != 10 )
   {
     alert( "Please provide a Mobile No in the format 123." );
     document.mobilenumbervalidation.mobileno.focus() ;

     return false;
   }
  if( document.mobilenumbervalidation.phoneno.value == "" ||
          isNaN( document.mobilenumbervalidation.phoneno.value) ||
          document.mobilenumbervalidation.phoneno.value.length != 10 )
  {
    alert( "Please provide a Phone No in the format 123." );
    document.mobilenumbervalidation.phoneno.focus() ;
    return false;
  }
   var email = document.mobilenumbervalidation.email_id.value;
  atpos = email.indexOf("@");
  dotpos = email.lastIndexOf(".");
 if (email == "" || atpos < 1 || ( dotpos - atpos < 2 ))
 {
     alert("Please enter correct email ID");
     document.mobilenumbervalidation.email_id.focus() ;
     return false;
 }

 return( true );
}
</script>


XML
<table   border="1"  bgcolor="#585858" width="20%"  align="center">
        <tr>
        <td>MobileNo</td>
        <td><input type="text" name="mobileno" id="mobileno" size="30"></td>
    </tr>
     <tr>
        <td>Phone No</td>
        <td><input type="text" name="phoneno" id="phoneno" size="30"></td>
     </tr>
    <tr>
        <td>Email_id</td>
        <td><input type="text" name="email_id" id="email_id"  size="30"></td>
    </tr>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900