Guest User

Untitled

a guest
Jul 24th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. <html>
  2. <title>
  3. question 2
  4. </title>
  5. </head>
  6. <script type ="text/javascript">
  7. //check fields
  8. function check(input)
  9. {
  10.  
  11. if(input.value.length == 0)
  12. {
  13. //check if the empty value = first name
  14. if(input.id == "firstname")
  15. {
  16. alert("Enter a first name please ");
  17. }
  18. if (input.id == "lastname")
  19. {
  20. alert("Enter a Last name please ");
  21. }
  22.  
  23. if (input.id == "address")
  24. {
  25. alert("Enter a address please ");
  26. }
  27. if (input.id == "state")
  28. {
  29. alert("Enter a state");
  30. }
  31. if (input.id == "zip")
  32. {
  33. alert("please enter a zip");
  34. }
  35.  
  36.  
  37. }
  38.  
  39. }
  40. function checkZip()
  41. {
  42. //get the zip data
  43. var zipLen = document.getElementById("zip").value.length;
  44. var zip = document.getElementById("zip").value;
  45. var min =00000;
  46. var max = 99999;
  47.  
  48. if(zipLen !=5)
  49. {
  50. alert("Sorry Please Enter exactly 5 digits");
  51. }
  52. if(isNaN(zip))
  53. {
  54. alert("Please Enter a number ");
  55. }
  56. if(!((zip > min) && (zip<max)))
  57. {
  58. alert("The Zip code must be over 00000 and below 99999");
  59. }
  60.  
  61. }
  62.  
  63. function checkAlpha()
  64. {
  65. var exp = /^[a-zA-Z]+$/;
  66. var aLen = document.getElementById("firstname").value.length;
  67. if(!(document.getElementById("firstname").value.match(exp)))
  68. {
  69. alert("Sorry the first name field needs to be letters !");
  70.  
  71. }
  72. else if(aLen < 3)
  73. {
  74. alert("Sorry the Name has to be greater than two letters");
  75. }
  76. }
  77.  
  78. </script>
  79.  
  80. </head>
  81. <body>
  82. <!-- text input! --->
  83. <form name = fom1 onsubmit="">
  84. <fieldset><legend align ='left'><b>Personal Information</b></legend>
  85. <table cellpadding ='2'>
  86. <tr>
  87. <td>
  88. First Name :
  89. </td>
  90. <td>
  91. <input type = "text" id = "firstname" onblur ="check(document.getElementById('firstname'));checkAlpha();"/>
  92. </td>
  93. <td>
  94. Last Name :
  95. </td>
  96. <td>
  97. <input type = 'text' id = 'lastname' onblur ="check(document.getElementById('lastname'));"/>
  98. </td>
  99. <td>
  100. </tr>
  101. <tr>
  102. <td>
  103. Address :
  104. </td>
  105. <td>
  106. <input type = "text" id = "address" onblur ="check(document.getElementById('address'));"/></br>
  107. </td>
  108. <td>
  109. State :
  110. </td>
  111. <td>
  112. <input type = 'text' id ='state'onblur ="check(document.getElementById('state'));"/>
  113. </td>
  114. <td>
  115. Zip :
  116. </td>
  117. <td>
  118. <input type = "text" id = "zip" onblur ="check(document.getElementById('zip'));checkZip();"/>
  119. </td>
  120. <td>
  121. <input type ="submit" value ="submit" />
  122. </td>
  123. </tr>
  124. </table>
  125. </fieldset>
  126. </form>
  127. </table>
  128. </fieldset>
  129. </body>
  130. </html>
Add Comment
Please, Sign In to add comment