Advertisement
Guest User

Untitled

a guest
Mar 4th, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.65 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2.  
  3. <html>
  4.  
  5. <head>
  6. <title>Modello di registrazione</title>
  7. <link rel="stylesheet" type="text/css" href="Modello_Registrazione.css">
  8. <script type='text/javascript'>
  9. function validateName(nome) {
  10.  
  11. var re = /[a-zA-Z]$/;
  12. if(re.test(document.modulo.getElementById("nome").value)){
  13. document.modulo.getElementById("nome").style.background = '#ccffcc';
  14. return true;
  15.  
  16. }else{
  17.  
  18. document.modulo.getElementById("nome").style.background = '#e35152';
  19. return false;
  20. }
  21.  
  22. }
  23. function validateSurname(cognome) {
  24.  
  25. var re = /[a-zA-Z]$/;
  26. if(re.test(document.modulo.getElementById("cognome").value)){
  27. document.modulo.getElementById("cognome").style.background = '#ccffcc';
  28. return true;
  29.  
  30. }else{
  31.  
  32. document.modulo.getElementById("cognome").style.background = '#e35152';
  33. return false;
  34. }
  35.  
  36. }
  37. function validateEmail(email){
  38. var re = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
  39. if(re.test(document.modulo.getElementById("email").value)){
  40.  
  41. document.modulo.getElementById("email").style.background = '#ccffcc';
  42. return true;
  43.  
  44. }else{
  45. document.modulo.getElementById("email").style.background = '#e35152';
  46. return false;
  47.  
  48.  
  49. }
  50. }
  51. function validateDataNascita(datanascita){
  52.  
  53.  
  54. var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
  55. if(!re.test(document.modulo.getElementById("datamascita").value)){
  56. document.modulo.getElementById("datamascita").style.background = '#e35152';
  57. return false;
  58. }else{
  59. document.modulo.getElementById("datamascita").style.background = '#ccffcc';
  60. return true;
  61. }
  62. var parts = dateString.split("/");
  63. var day = parseInt(parts[1], 10);
  64. var month = parseInt(parts[0], 10);
  65. var year = parseInt(parts[2], 10);
  66.  
  67.  
  68. if(year < 1000 || year > 3000 || month == 0 || month > 12){
  69. return false;
  70. }
  71. var monthLength = [ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 ];
  72.  
  73.  
  74. if(year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)){
  75. monthLength[1] = 29;
  76.  
  77.  
  78. return day > 0 && day <= monthLength[month - 1];
  79. }
  80. }
  81. function validateUsername(username){
  82. var re = /[a-zA-Z]$/
  83. var uInput = /^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-])/;
  84. if(uInput.test(document.modulo.getElementById("username").value)){
  85. document.modulo.getElementById("username").style.background = '#ccffcc';
  86. return true;
  87. }
  88. if(re.test(document.modulo.getElementById("username").value)){
  89. document.modulo.getElementById("username").style.background = '#ccffcc';
  90. alert ("Username must contain two letters from name,two letters from surname and the year of your birthday");
  91. return false;
  92.  
  93. }
  94.  
  95. }
  96. function validateSex(msex,fsex)
  97. {
  98. x=0;
  99.  
  100. if(dovument.modulo.getElementById("msex").checked)
  101. {
  102. x++;
  103. } if(document.modulo.getElementById("fsex").checked)
  104. {
  105. x++;
  106. }
  107. if(x==0)
  108. {
  109. alert('Select Male/Female');
  110. return false;
  111. }
  112.  
  113. }
  114. function validatePassword(pwd1,8,20)
  115. {
  116. var pwd_len = document.modulo.getElementById("pwd1").value.length;
  117. if (pwd_len == 0 ||pwd_len >= 20 || pwd_len < 8)
  118. {
  119. alert ("Password should not be empty / length be between "8" to "20" ");
  120.  
  121. return false;
  122. }
  123. return true;
  124. if(pwd_len == 8){
  125. alert ("Weak password");
  126. }
  127. if(pwd_len == 15){
  128. alert ("Good password");
  129. }
  130. if(pwd_len == 20){
  131. alert ("Very strong password");
  132. }
  133. }
  134. function validateConfirmaPassword(pwd2,8.20)
  135. {
  136. var pwd_len = document.modulo.getElementById("pwd2").value.length;
  137. if (pwd_len == 0 ||pwd_len >= 20 || pwd_len < 7)
  138. {
  139. alert ("Password should not be empty / length be between "8" to "20" ");
  140.  
  141. return false;
  142. }
  143. return true;
  144. if(pwd_len == 8){
  145. alert ("Weak password");
  146. }
  147. if(pwd_len == 15){
  148. alert ("Good password");
  149. }
  150. if(pwd_len == 20){
  151. alert ("Very strong password");
  152. }
  153. }
  154. function validateForm() {
  155. var nome = document.modulo.getElementById('nome').value;
  156. var cognome = document.modulo.getElementById('cognome').value;
  157. var email = document.modulo.getElementById('email').value;
  158. var datanascita = document.modulo.getElementById('datanascita').value;
  159. var username = document.modulo.getElementById('username').value;
  160. var sesso1 = document.modulo.getElementById('msex').value;
  161. var sesso2 = document.modulo.getElementById('fsex').value;
  162. var password = document.modulo.getElementById('pwd1').value;
  163. var confermaPassword = document.modulo.getElementById('pwd2').value;
  164.  
  165. if(validateName(nome)){
  166. if(validateSurname(cognome)){
  167. if(validateEmail(email)){
  168. if(validateDataNascita(datanascita)){
  169. if(validateUsername(username)){
  170. if(validateSex(sesso1,sesso2)){
  171. if(validatePassword(password)){
  172. if(validateConfermaPassword(confermaPassword)){
  173. return true;
  174. }
  175. }
  176. }
  177. }
  178. }
  179. }
  180. }
  181. }
  182.  
  183. return false;
  184.  
  185. }
  186. </script>
  187. </head>
  188.  
  189. <body>
  190. <h1>Registrazione</h1>
  191. <br/>
  192. <form action="" name="modulo" onsubmit="return validateForm()">
  193. <fieldset>
  194. <legend>Dati : </legend>
  195. <table border="0">
  196. <tr>
  197. <td>Nome : </td><td><input type="text" id="nome" /></td>
  198. </tr>
  199. <tr>
  200. <td>Cognome :</td><td><input type="text" id="cognome" /></td>
  201. </tr>
  202. <tr>
  203. <td>E_mail : </td><td><input type="text" id="email" /></td>
  204. </tr>
  205. <tr>
  206. <td>Data di nascita : </td><td><input type="date" id:"datanascita" /></td>
  207. </tr>
  208. <tr>
  209. <td>UserName : </td><td><input type="text" id="username" /></td>
  210. </tr>
  211. <tr>
  212. <td rowspan="2">Sesso : </td><td><input type="radio" id="msex" />M</td>
  213.  
  214. </tr>
  215. <tr>
  216. <td><input type="radio" id="fsex" />F</td>
  217. </tr>
  218. <tr>
  219. <td>Password : </td><td><input type="password" id="pwd1" /></td>
  220. </tr>
  221. <tr>
  222. <td>Conferma Password : </td><td><input type="password" id="pwd2" /></td>
  223. </tr>
  224. <tr>
  225. <td colspan="2" align="middle"><input type="submit" value="SUBMIT" /></td>
  226. </tr>
  227. </table>
  228. </fieldset>
  229. </form>
  230.  
  231. </body>
  232.  
  233. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement