When the user provides critical Information, then Validation is an essential part. With Javascript code, it can validate name, email, password, etc. This ensures the user's authenticity.
If the email validation on the client side is completed, then processing of data on server side validation is also somewhat faster.
Email Format: personal_data@domain_name
- -The length of personal info can be up to 64 characters.
- -The domain name can be up to 253 characters
Personal Data Includes: Uppercase (A-Z) and Lowercase letters(a-z) of the alphabet, digits(0-9), characters ( ! # $ % & ' * + - / = ? ^ _ ` { | } ~ ) and the character (.)
Example:
<form>
<input type="text" id="email_text" name="email_text">
<button type="submit" onclick="validate()">Submit</button>
</form>
<script type="text/javascript">
function validate() {
var email = document.getElementById('email_text').value;
const regx = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if(regx.test(email)){
alert("Email is Valid");
return true;
}else{
alert("Email is Invalid");
return true;
}
}
</script>