Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //function checks for empty fields
- function CheckEmpty(field_id){
- //
- var MyValue = document.getElementById(field_id);
- if(MyValue.value == "" || MyValue.value == null){
- //code
- displayWarning(field_id, MyValue.parentNode.id, "You can't leave this empty.");
- }
- }
- //function validates the given email id
- function ValidateEmail(email){
- var MyEmail = document.getElementById(email);
- var format = /.+@.+/;
- if(!MyEmail.value.match(format)){
- displayWarning(email, MyEmail.parentNode.id, "Please enter a valid email.");
- };
- }
- //function validates the password field
- function ValidatePassword(password){
- var MyPassword=document.getElementById(password);
- var format = /(?=^.{8,}$)(?=.*\d)(?=.*[!@#$%^&*]+)(?![.\n])(?=.*[A-Z])(?=.*[a-z]).*$/;
- if(!MyPassword.value.match(format)){
- displayWarning(password, MyPassword.parentNode.id, "The password must be a combination of Uppercase, Lowercase, Numbers, Special characters and at least 8 characters long.");
- }
- }
- //function confirms that passwords are the same
- function ConfirmPassword(password, confirm_password){
- var Password=document.getElementById(password);
- var ConfirmPassword = document.getElementById(confirm_password);
- if(ConfirmPassword.value !== Password.value){
- displayWarning(confirm_password, ConfirmPassword.parentNode.id, "Please enter the same password in both fields.");
- }
- }
- //function checks the checkboxes
- function ValidateCheckbox(checkbox){
- var check_box = document.getElementById(checkbox);
- if(check_box.checked == false){
- //code
- displayWarning(checkbox, check_box.parentNode.parentNode.id, "You must agree to proceed.");
- }
- }
- //function validates the selections
- function ValidateSelect(select){
- //code
- selected = document.getElementById(select);
- if(selected.selectedIndex == 0){
- //code
- displayWarning(select, selected.parentNode.id, "Please select your country.");
- }
- }
- //function displays the error message
- function displayWarning(field_id, parent_div, message){
- var x = document.getElementById(parent_div).querySelectorAll(".warning_msg").length;
- if(x === 0 ){
- var para = document.createElement("p");
- para.setAttribute("class","warning_msg");
- var error_msg = document.createTextNode(message);
- para.appendChild(error_msg);
- document.getElementById(parent_div).appendChild(para);
- document.getElementById(field_id).className += " warning_brd";
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment