Advertisement
Locoluis

Regular Expression Test

Jul 5th, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.46 KB | None | 0 0
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Regex Test</title>
  6. <style>
  7. body {
  8.     background: #eee;
  9.     color: #333;
  10.     font-family: Georgia, serif;
  11.     font-size: 16px;
  12. }
  13. form, #message {
  14.     border: solid 1px #999;
  15.     padding: 8px;
  16.     width: 200px;
  17.     text-align: center;
  18.     margin: 16px auto;
  19.     background: white;
  20.     -webkit-border-radius: 4px;
  21.     -moz-border-radius: 4px;
  22.     border-radius: 4px;
  23. }
  24. input {
  25.     font-size: 16px;
  26.     width: 112px;
  27. }
  28. h1 {
  29.     text-align: center;
  30.     border-bottom: solid 1px #555;
  31.     line-height: 48px;
  32.     width: 300px;
  33.     text-align: center;
  34.     margin-left: auto;
  35.     margin-right: auto;
  36. }
  37. </style>
  38. <script>
  39. var fadetimeout = null;
  40. function validate(data)
  41. {
  42.     if(fadetimeout != null) {
  43.         clearTimeout(fadetimeout);
  44.     }
  45.     var msg = document.getElementById('message');
  46.     if(data.match(/^([A-Za-z0-9][A-Za-z]|[A-Za-z][A-Za-z0-9])$/)) {
  47.         msg.innerHTML = "Your input is valid";
  48.         msg.style.borderColor = "green";
  49.         msg.style.display = "";
  50.     } else {
  51.         msg.innerHTML = "Your input is incorrect";
  52.         msg.style.borderColor = "red";
  53.         msg.style.display = "";
  54.     }
  55.     fadetimeout = setTimeout(function() {
  56.         msg.style.display = "none";
  57.         fadetimeout = null;
  58.     }, 2000);
  59.     return false;
  60. }
  61. </script>
  62. </head>
  63. <body>
  64. <h1>Regex Test</h1>
  65. <form action="#" onsubmit="return validate(this.data.value);">
  66. Input: <input type="text" name="data" value="" onblur="validate(this.value);return true;">
  67. </form>
  68. <div id="message" style="display: none"></div>
  69. </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement