Javascript 4 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 Javascript 4 Validations as PDF for free.

More details

  • Words: 888
  • Pages: 6
<script type="text/javascript"> //function validezip(zip) //{ //var regexp_zip=\d{5}(-\d{4})?; //return true; //} function validform() { if(document.getelementbyid("txtname").value.length<1) { alert("please provide \"name\""); document.getelementbyid("txtname").focus(); return false;} if(document.getelementbyid("txtsocial").value.length<1) { alert("please provide \"social security number\""); document.getelementbyid("txtsocial").focus(); return false;} if(document.getelementbyid("txtsocial").value.match(/^\d{3}-\d{2}\d{4}/)==null) { alert("\"social security\"only number"); return false; } if(document.getelementbyid("txtphone").value.length<1) { alert("please provide \"phone number\""); document.getelementbyid("txtphone").focus(); return false;} if (document.getelementbyid("txtphone").value.length < 10) { alert("minimum length for \"phone number\" is 10"); document.getelementbyid("txtphone").focus(); return false; } var charpos = document.getelementbyid("txtphone").value.search("[^09]"); if(charpos >= 0) { alert("\"phone number\" only allows numbers"); document.getelementbyid("txtphone").focus(); return false; } if(document.getelementbyid("txtaddress").value.length<1) { alert("please provide \"address\""); document.getelementbyid("txtaddress").focus(); return false; } if(document.getelementbyid("txtcity").value.length<1) { alert("plesae provide\"city name\""); document.getelementbyid("txtcity").focus(); return false;} if(document.getelementbyid("txtstate").value.length<1) {alert("please provide\"state name\""); document.getelementbyid("txtstate").focus(); return false;} if(document.getelementbyid("txtzip").value.length<1) {alert("please provide\"zipcode\""); document.getelementbyid("txtzip").focus(); return false;} if (document.getelementbyid("txtzip").value.length < 5) { alert("length for \"zip code\" is 5"); document.getelementbyid("txtzip").focus(); return false; } if (document.getelementbyid("txtzip").value.length > 5) { alert("length for \"zip code\" is 5");

document.getelementbyid("txtzip").focus(); return false; } var charzip = document.getelementbyid("txtzip").value.search("[^09]"); if(charzip >= 0) { alert("\"enter valid zip code\" only allow numbers"); document.getelementbyid("txtzip").focus(); return false; } if(document.getelementbyid("txtposition").value.length<1) { alert("please provide \"position applied for\""); document.getelementbyid("txtposition").focus(); return false;} if(document.getelementbyid("txtexpected").value.length<1) { alert("please provide \"expected pay\""); document.getelementbyid("txtexpected").focus(); return false;} if(document.getelementbyid("txtwhatdate").value.length<1) { alert("please provide \"on what date would you be available for work?\""); document.getelementbyid("txtwhatdate").focus(); return false;} if(document.getelementbyid("txtsptraining").value.length<1) { alert("please provide \"special training or skills:\""); document.getelementbyid("txtsptraining").focus(); return false;} if(document.getelementbyid("txtemployer1").value.length<1) { alert("please provide \"employer\""); document.getelementbyid("txtemployer1").focus(); return false;} if(document.getelementbyid("txtaddress1").value.length<1) { alert("please provide \"address\""); document.getelementbyid("txtaddress1").focus(); return false;} if(document.getelementbyid("txtphoneemp1").value.length<1) { alert("please provide \"phone\""); document.getelementbyid("txtphoneemp1").focus(); return false;} if (document.getelementbyid("txtphoneemp1").value.length < 10) { alert("minimum length for \"phone number\" is 10"); document.getelementbyid("txtphoneemp1").focus(); return false; } var charpos1=document.getelementbyid("txtphoneemp1").value.search("[0,9]"); if(charpos1>=0) { alert("\"phone number of employer first"); document.getelementbyid("txtphoneemp1").focus(); return false; } if(document.getelementbyid("txtjob1").value.length<1) { alert("please provide \"job title\""); document.getelementbyid("txtjob1").focus(); return false;} if(document.getelementbyid("txtsupervisor1").value.length<1) { alert("please provide \"supervisor\""); document.getelementbyid("txtsupervisor1").focus(); return false;} if(document.getelementbyid("txtdateemployed1").value.length<1) { alert("please provide \"date employed\""); document.getelementbyid("txtdateemployed1").focus(); return false;} if(document.getelementbyid("txthratestarting1").value.length<1) { alert("please provide \"hourly rate/salary-starting\""); document.getelementbyid("txthratestarting1").focus(); return false;} if(document.getelementbyid("txthratefinal1").value.length<1) { alert("please provide \"hourly rate/salary-final \""); document.getelementbyid("txthratefinal1").focus(); return false;}

if(document.getelementbyid("txtworkperformed1").value.length<1) { alert("please provide \"work performed \""); document.getelementbyid("txthratefinal1").focus(); return false;} if(document.getelementbyid("txtreasonleaving1").value.length<1) { alert("please provide \"reason for leaving\""); document.getelementbyid("txtreasonleaving1").focus(); return false;} if(document.getelementbyid("txtemployer2").value.length<1) { alert("please provide \"employer \""); document.getelementbyid("txtemployer2").focus(); return false;} if(document.getelementbyid("txtaddress2").value.length<1) { alert("please provide \"address \""); document.getelementbyid("txtaddress2").focus(); return false;} if(document.getelementbyid("txtphone2").value.length<1) { alert("please provide \"phone\""); document.getelementbyid("txtphone2").focus(); return false;} if (document.getelementbyid("txtphone2").value.length < 10) { alert("minimum length for \"phone number\" is 10"); document.getelementbyid("txtphone2").focus(); return false; } var charpos2 = document.getelementbyid("txtphone2").value.search("[^09]"); if(charpos2 >= 0) { alert("\"phone number of employer second\" only allows numbers"); document.getelementbyid("txtphone2").focus(); return false; } if(document.getelementbyid("txtjob2").value.length<1) { alert("please provide \"job title\""); document.getelementbyid("txtjob2").focus(); return false;} if(document.getelementbyid("txtsupervisor2").value.length<1) { alert("please provide \"supervisor\""); document.getelementbyid("txtsupervisor2").focus(); return false;} if(document.getelementbyid("txtdateemplyed2").value.length<1) { alert("please provide \"date employed\""); document.getelementbyid("txtdateemplyed2").focus(); return false;} if(document.getelementbyid("txthratestarting2").value.length<1) { alert("please provide \"hourly rate/salary-starting\""); document.getelementbyid("txthratestarting2").focus(); return false;} if(document.getelementbyid("txthratefinal2").value.length<1) { alert("please provide \"hourly rate/salary-final \""); document.getelementbyid("txthratefinal2").focus(); return false;} if(document.getelementbyid("txtworkperformed2").value.length<1) { alert("please provide \"work performed \""); document.getelementbyid("txthratefinal2").focus(); return false;} if(document.getelementbyid("txtreasonleaving2").value.length<1) { alert("please provide \"reason for leaving\""); document.getelementbyid("txtreasonleaving2").focus(); return false;} if(document.getelementbyid("txtschoolgrammer").value.length<1) { alert("please provide \"name of school\""); document.getelementbyid("txtschoolgrammer").focus(); return false;} if(document.getelementbyid("txtlocationgrammer").value.length<1) { alert("please provide \" location\""); document.getelementbyid("txtlocationgrammer").focus(); return false;} if(document.getelementbyid("txtcoursegrammer").value.length<1) { alert("please provide \"course of study\""); document.getelementbyid("txtcoursegrammer").focus(); return false;} if(document.getelementbyid("txtdegreehigh").value.length<1) { alert("please provide \"degree or diploma \"");

document.getelementbyid("txtdegreehigh").focus(); return false;} if(document.getelementbyid("txtschoolnamehigh").value.length<1) { alert("please provide \"name of school \""); document.getelementbyid("txtschoolnamehigh").focus(); return false;} if(document.getelementbyid("txtlocationcollege").value.length<1) { alert("please provide \" location\""); document.getelementbyid("txtlocationcollege").focus(); return false;} if(document.getelementbyid("txtcoursecollege").value.length<1) { alert("please provide \"course of study\""); document.getelementbyid("txtcoursecollege").focus(); return false;} if(document.getelementbyid("txtdegreecollege").value.length<1) { alert("please provide \"degree or diploma \""); document.getelementbyid("txtdegreecollege").focus(); return false;} if(document.getelementbyid("txtschoolgraduate").value.length<1) { alert("please provide \" name of school\""); document.getelementbyid("txtschoolgraduate").focus(); return false;} if(document.getelementbyid("txtlocationgraduate").value.length<1) { alert("please provide \" location\""); document.getelementbyid("txtlocationgraduate").focus(); return false;} if(document.getelementbyid("txtcoursegraduate").value.length<1) { alert("please provide \"course of study\""); document.getelementbyid("txtcoursegraduate").focus(); return false;} if(document.getelementbyid("txtdegreegraduate").value.length<1) { alert("please provide \"degree or diploma \""); document.getelementbyid("txtdegreegraduate").focus(); return false;} if(document.getelementbyid("txtconteducation").value.length<1) { alert("please provide \"continuing education\""); document.getelementbyid("txtconteducation").focus(); return false;}

}

for email-----------------> function validateemailv2(email) { var splitted = email.match("^(.+)@(.+)$"); if(splitted == null) return false; if(splitted[1] != null ) { var regexp_user=/^\"?[\w-_\.]*\"?$/; if(splitted[1].match(regexp_user) == null) return false; } if(splitted[2] != null) { var regexp_domain=/^[\w-\.]*\.[a-za-z]{2,4}$/; if(splitted[2].match(regexp_domain) == null) { var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;

if(splitted[2].match(regexp_ip) == null) return false;

} return true;

}

} return false;

if(document.getelementbyid("txtemail").value.length<1) { alert("please provide \"email\""); document.getelementbyid("txtemail").focus(); return false;} if(!validateemailv2(document.getelementbyid("txtemail").value)) { alert("enter valid email address"); document.getelementbyid("txtemail").focus(); return false; }

if(document.getelementbyid("txtemail").value.length<1) { alert("please provide \"email\""); document.getelementbyid("txtemail").focus(); return false;} if(!validateemailv2(document.getelementbyid("txtemail").value)) { alert("enter valid email address"); document.getelementbyid("txtemail").focus(); return false; }

----------------------------------------------------------------------------------------------------------------------------tips on javascript: -----------------.

opens a pop up window after 1 minute

settimeout(window.open("page.aspx", "windowname", "width=100, height=100, left=0, top=0, menubar=no, status=no, left=100,top=100,toolbar=no, scrollbars=no, resizable=yes",10000) 2.

refresh the page by every 1 minute

settimeout("location.href = 'refreshpage.html'",10000) 3. to close the popup window after 5 minutes settimeout('popup.close()',50000) or close the current window after 5 minutes

settimeout('window.close()',50000) 4. to dynamically resize the window window.resizeto(200,200) decrease the height and width

of the window by 25

window.resizeby(-25,-25) increase the height and width of the window by 25 window.resizeby(25,25)

----------------------------------------------------------------------------------------------------------------------clock at status bar < script language="javascript" >function doclock() { window.settimeout( "doclock()", 1000 ); today = new date(); self.status = today.tostring();}doclock()< /script > here doclock() call function doclock. the window object supports methods for setting timers that we might use to perform a variety of functions. these methods include settimeout() and cleartimeout(). the basic idea is to set a timeout to trigger a piece of script to occur at a particular time in the future. the general syntax is timerid = settimeout(script-to-execute, time-in-milliseconds); here window.settimeout( "doclock()", 1000 ); today = new date(); self.status = today.tostring(); after 1000 milliseconds windows.settimeout() call to doclock(). the date object provides a sophisticated set of methods for manipulating dates and times. and then it converted to string and display at status bar.

Related Documents

Javascript 4 Validations
November 2019 11
Validations
November 2019 9
Validations
November 2019 32
Javascript 4
November 2019 8