Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <title>
- question 2
- </title>
- </head>
- <script type ="text/javascript">
- //check fields
- function check(input)
- {
- if(input.value.length == 0)
- {
- //check if the empty value = first name
- if(input.id == "firstname")
- {
- alert("Enter a first name please ");
- }
- if (input.id == "lastname")
- {
- alert("Enter a Last name please ");
- }
- if (input.id == "address")
- {
- alert("Enter a address please ");
- }
- if (input.id == "state")
- {
- alert("Enter a state");
- }
- if (input.id == "zip")
- {
- alert("please enter a zip");
- }
- }
- }
- function checkZip()
- {
- //get the zip data
- var zipLen = document.getElementById("zip").value.length;
- var zip = document.getElementById("zip").value;
- var min =00000;
- var max = 99999;
- if(zipLen !=5)
- {
- alert("Sorry Please Enter exactly 5 digits");
- }
- if(isNaN(zip))
- {
- alert("Please Enter a number ");
- }
- if(!((zip > min) && (zip<max)))
- {
- alert("The Zip code must be over 00000 and below 99999");
- }
- }
- function checkAlpha()
- {
- var exp = /^[a-zA-Z]+$/;
- var aLen = document.getElementById("firstname").value.length;
- if(!(document.getElementById("firstname").value.match(exp)))
- {
- alert("Sorry the first name field needs to be letters !");
- }
- else if(aLen < 3)
- {
- alert("Sorry the Name has to be greater than two letters");
- }
- }
- </script>
- </head>
- <body>
- <!-- text input! --->
- <form name = fom1 onsubmit="">
- <fieldset><legend align ='left'><b>Personal Information</b></legend>
- <table cellpadding ='2'>
- <tr>
- <td>
- First Name :
- </td>
- <td>
- <input type = "text" id = "firstname" onblur ="check(document.getElementById('firstname'));checkAlpha();"/>
- </td>
- <td>
- Last Name :
- </td>
- <td>
- <input type = 'text' id = 'lastname' onblur ="check(document.getElementById('lastname'));"/>
- </td>
- <td>
- </tr>
- <tr>
- <td>
- Address :
- </td>
- <td>
- <input type = "text" id = "address" onblur ="check(document.getElementById('address'));"/></br>
- </td>
- <td>
- State :
- </td>
- <td>
- <input type = 'text' id ='state'onblur ="check(document.getElementById('state'));"/>
- </td>
- <td>
- Zip :
- </td>
- <td>
- <input type = "text" id = "zip" onblur ="check(document.getElementById('zip'));checkZip();"/>
- </td>
- <td>
- <input type ="submit" value ="submit" />
- </td>
- </tr>
- </table>
- </fieldset>
- </form>
- </table>
- </fieldset>
- </body>
- </html>
Add Comment
Please, Sign In to add comment