Validations

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Validations as PDF for free.

More details

  • Words: 551
  • Pages: 5
Special Charecters: var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?"; for (var i = 0; i < document.formname.fieldname.value.length; i++) { if (iChars.indexOf(document.formname.fieldname.value.charAt(i)) != -1) { alert ("Your username has special characters. \nThese are not allowed.\n Please remove them and try again."); return false; } } -----------------------------------------------------------Alpha , Numeric & Special Charecter <script language="javascript"> function isStrongPassword() { var control = document.form1.password; var myString= control.value; var Stringlen = myString.length; var ValidateDigits = /[^0-9]/g; var ValidateSpChar = /[a-zA-Z0-9]/g; var ValidateChar = /[^a-zA-Z]/g; var digitString = myString.replace(ValidateDigits , ""); var specialString = myString.replace(ValidateSpChar, ""); var charString = myString.replace(ValidateChar, ""); if(Stringlen < 8) { alert("Passwords must be at least 8 characters"); control.value=""; control.focus(); return false; } if(specialString < 1) { alert("Passwords must include at least 1 special (#,@,&,$ etc) characters"); control.value=""; control.focus();

return false; } if(digitString < 1) { alert("Passwords must include at least 1 numeric characters"); control.value=""; control.focus(); return false; } return; }

Registration

Login:
Password:



-----------------------------------------<script language="JavaScript">

E-Mail format checking script.

-------------------------------------------------------------------------------if (document.formname.fieldname.value.length >0) { i=document.formname.fieldname.value.indexOf("@") j=document.formname.fieldname.value.indexOf(".",i) k=document.formname.fieldname.value.indexOf(",") kk=document.formname.fieldname.value.indexOf(" ") jj=document.formname.fieldname.value.lastIndexOf(".")+1 len=document.formname.fieldname.value.length if ((i>0) && (j>(1+1)) && (k==-1) && (kk==-1) && (len-jj >=2) && (lenjj<=3)) { } else { alert("Please enter an exact email address.\n" + document.formname.fieldname.value + " is invalid."); return false; } } Check if field has special characters. -------------------------------------------------------------------------------var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?"; for (var i = 0; i < document.formname.fieldname.value.length; i++) { if (iChars.indexOf(document.formname.fieldname.value.charAt(i)) != -1) { alert ("Your username has special characters. \nThese are not allowed.\n Please remove them and try again."); return false; } } Check if certian radio buttons have not been selected. -------------------------------------------------------------------------------if (!document.formname.fieldname[0].checked && !document.formname.fieldname[1].checked && !document.formname.fieldname[2].checked && !document.formname.fieldname[3].checked) { alert("Please choose a group designation.\n");

return false; } Check if textbox has any characters in it. -------------------------------------------------------------------------------if (document.formname.fieldname.value.length == 0) { alert("Please fill out your name.\n"); return false; } Check if multiple checkboxes have not been selected.Replace false with true to see if all are selected. -------------------------------------------------------------------------------if (document.formname.fieldname.checked == false && document.formname.fieldname.checked == false && document.formname.fieldname.checked == false) { alert("Please select at least one checkbox.\n"); return false; } Check drop down has been selected. Set drop down's value to Not_Selected for this to work. -------------------------------------------------------------------------------if (document.formname.fieldname.value == 'Not_Selected') { alert("Please provide us with a selection.\n"); return false; } Scan values in a field and if they are all letters then alert. The second block of code does the same but for numbers -------------------------------------------------------------------------------//alert on finding all letters var noalpha = /^[a-zA-Z]*$/;

if (noalpha.test(document.formname.fieldname.value)) { alert("Please enter at least one number in the \"username\" field."); return false; } //alert on finding all numbers var nonums = /^[0-9]*$/; if (nonums.test(document.formname.fieldname.value)) { alert("Please enter at least one letter in the \"username\" field."); return false; } Remove special characters from a string. -------------------------------------------------------------------------------function clearText() { document.formname.fieldname.value=filterNum(document.formname.fieldname.valu e) function filterNum(str) { re = /\$|, ~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g; // remove special characters like "$" and "," etc... return str.replace(re, ""); } } Detect special characters in text box. Or any character you subsitute for the special characters. -------------------------------------------------------------------------------var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?"; for (var i = 0; i < document.formname.fieldname.value.length; i++) { if (iChars.indexOf(document.formname.fieldname.value.charAt(i)) != -1) { alert ("The box has special characters. \nThese are not allowed.\n"); return false; } }

Related Documents

Validations
November 2019 9
Validations
November 2019 32
Validations Eswar December
November 2019 29
Javascript 4 Validations
November 2019 11