Email Validation In Javascript

Email Validation In Javascript

Email Validation In Javascript is extremely useful and you can validate input before Submitted. Email Validation In Javascript, you will look at how to use the on submit event handler with the return statement as well as learn some validation Techniques.

Email Validation In Javascript

Also Read : 8085 Microprocessor

Email Validation In Javascript | To validate the contents of one or more elements in a form, you need to know when the viewer tries to submit the form. When the viewer clicks the submit button, a submit event occurs,which can be captured with the on submit event handler in the opening form tag.Thus, the following form would be able to do something when the submit button is clicked, before acting on its action attribute:

 <script>  
function validateemail()  
{  
var x=document.myform.email.value;  
var atposition=x.indexOf("@");  
var dotposition=x.lastIndexOf(".");  
if (atposition<1 || dotposition<atposition+2 || dotposition+2>=x.length){  
  alert("Please enter a valid e-mail address "+atposition+" "+dotposition);  
  return false;  
  }  
}  
</script>  
  
<form name="myform"  method="post" action=" " onsubmit="return validateemail();">  
Email: <input type="text" name="email"><br/>  
  
<input type="submit" value="register">  
</form> 

Also Read : Dry Fruits Name

Email Validation In Javascript | For the Function to do its work, however, you must be sure the submit button is not able to perform its default action if the viewer’s input doesn’t pass the validation. This means that you need a return statement in the on submits event handler. You want this statement to return true if the validation passes and to return false if the validation fails.

A number of these properties and methods are used with all of the element types, while only a few are more specific. As you continue to write scripts, you will start to know which elements have which properties and methods so it won’t be as confusing. If you notice which properties and methods are used with each element, it will be easier to see when there is one that is specific to a certain type of element.   

Email Validation In Javascript | In some of these cases, you will already have your own values built into the elements. However, if you can, you should still validate those values against other information to be sure the information you receive matches your needs. 

You just need to adjust your function to perform the needed tasks based on the different types of input devices (text areas, radio buttons, and so on). For instance, the next section covers select boxes as they relate to navigation. However, some of the information (such as the selectedIndex property) is useful for validation as well.

For the most part, you can validate anything you like in the manner you see fit. You can validate dates, names, times, addresses, e-mail addresses, phone numbers, or anything else you might need.

Newest
Previous
Next Post »