Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset='utf-8'>
- <title>Input Field Validation</title>
- </head>
- <body>
- <p>Only numbers Letters And White space</p>
- <input type='text' onblur='inputValidation(this)'> <!-- Our Text Input Filed -->
- <br />
- <div id='textField'></div>
- </body>
- <script>
- function inputValidation(inputTxt){
- var regx = /^[0-9a-zA-Z ]+$/;
- var textField = document.getElementById("textField");
- if(inputTxt.value != '' ){
- if(inputTxt.value.length >= 5){
- if(inputTxt.value.match(regx)){
- textField.textContent = 'Good input';
- textField.style.color = "green";
- }else{
- textField.textContent = 'only numbers, letters And White space';
- textField.style.color = "red";
- }
- }else{
- textField.textContent = 'your input is less than 5 chracters';
- textField.style.color = "red";
- }
- }else{
- textField.textContent = 'your input is empty';
- textField.style.color = "red";
- }
- }
- </script>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement