Advertisement
Guest User

Untitled

a guest
Mar 30th, 2015
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. <!DOCTYPE html>
  2.  
  3. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  4. <head>
  5. <meta charset="utf-8" />
  6. <title></title>
  7.  
  8. <script>
  9. function validateInput(){
  10. var inputElement = document.getElementById('input').value;
  11.  
  12. trimString(inputElement);
  13.  
  14. var divElementForValidate = document.getElementById('theDiv').innerHTML;
  15.  
  16. divElementForValidate = inputElement;
  17. document.getElementById('theDiv').innerHTML = divElementForValidate;
  18.  
  19. var isValidEmail = validateEmail(inputElement);
  20. console.log(isValidEmail);
  21.  
  22. if (isValidEmail) {
  23. changeBackground('green');
  24. }
  25. else {
  26. changeBackground('red')
  27. }
  28.  
  29. }
  30.  
  31. function validateEmail(email) {
  32. var result = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
  33. //var result = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
  34. return result.test(email);
  35. }
  36.  
  37. function changeBackground(color) {
  38. var element = document.getElementById('theDiv');
  39. element.style.background = color;
  40. }
  41.  
  42. function trimString(string) {
  43. return string.trim();
  44. }
  45.  
  46. </script>
  47.  
  48. <style>
  49.  
  50.  
  51. </style>
  52. </head>
  53. <body>
  54.  
  55. <table>
  56. <tr>
  57. <td>
  58. <input id="input" type="text" name="name" value="" />
  59. <div id="theDiv"></div>
  60. <button type="button" onclick="validateInput()" onblur="this.value=removeSpaces(this.value)">Validate</button>
  61. </td>
  62. </tr>
  63. </table>
  64.  
  65.  
  66.  
  67.  
  68. </body>
  69. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement