Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8">
- <title>Regex Test</title>
- <style>
- body {
- background: #eee;
- color: #333;
- font-family: Georgia, serif;
- font-size: 16px;
- }
- form, #message {
- border: solid 1px #999;
- padding: 8px;
- width: 200px;
- text-align: center;
- margin: 16px auto;
- background: white;
- -webkit-border-radius: 4px;
- -moz-border-radius: 4px;
- border-radius: 4px;
- }
- input {
- font-size: 16px;
- width: 112px;
- }
- h1 {
- text-align: center;
- border-bottom: solid 1px #555;
- line-height: 48px;
- width: 300px;
- text-align: center;
- margin-left: auto;
- margin-right: auto;
- }
- </style>
- <script>
- var fadetimeout = null;
- function validate(data)
- {
- if(fadetimeout != null) {
- clearTimeout(fadetimeout);
- }
- var msg = document.getElementById('message');
- if(data.match(/^([A-Za-z0-9][A-Za-z]|[A-Za-z][A-Za-z0-9])$/)) {
- msg.innerHTML = "Your input is valid";
- msg.style.borderColor = "green";
- msg.style.display = "";
- } else {
- msg.innerHTML = "Your input is incorrect";
- msg.style.borderColor = "red";
- msg.style.display = "";
- }
- fadetimeout = setTimeout(function() {
- msg.style.display = "none";
- fadetimeout = null;
- }, 2000);
- return false;
- }
- </script>
- </head>
- <body>
- <h1>Regex Test</h1>
- <form action="#" onsubmit="return validate(this.data.value);">
- Input: <input type="text" name="data" value="" onblur="validate(this.value);return true;">
- </form>
- <div id="message" style="display: none"></div>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement