0

I have one requirement,user should enter text in asp.net text box only 'X-XXXX' format.user can enter text or numbers but should be this format. Can any one suggest JavaScript validation function

1
  • 1
    why dont you go with ajax tools maskededit extender?? Commented Dec 24, 2013 at 9:21

1 Answer 1

2

Assuming you have this HTML:

 <input id="foo"><span id='validationMessage'></span>

This javascript does the job:

var input = document.getElementById('foo');
var spanMessage = document.getElementById('validationMessage');
input.addEventListener('blur', function () {
    if (!input.value.match(/[a-z0-9]-[a-z0-9]{4}/i)) {
        if (spanMessage.firstChild) {                                                                                                                                                                                         
            spanMessage.removeChild(spanMessage.firstChild);
        }
        spanMessage.appendChild( document.createTextNode("Invalid input; must be X-XXXX"));
    } else {
        spanMessage.removeChild(spanMessage.firstChild);
    }
}, false);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.