0

I would like to create a textbox which accepts text in english only and integers. Basically I would like to restrict the input in a textbox to be English only.

I guess it should be something using the keydown event. But how do I restrict the input box to accept A-Z a-z and 0-9 only?

3
  • When you say English, do you mean Latin text? What about characters that have accents? Commented Mar 4, 2011 at 12:29
  • Be careful - a naïve algorithm may exclude valid words. Commented Mar 4, 2011 at 12:34
  • @Duniyadnd - just need a-z A-Z and 0-9 thats all Commented Mar 5, 2011 at 16:47

2 Answers 2

3

I would highly recommend the masked input plugin for jQuery.

Sign up to request clarification or add additional context in comments.

Comments

0

HI, You can use regex(Regular Expresssion) to match the required criteria inyour case only english characters and digits.

Below is a sample that you can try to understand the working of regex for javascript.

var myRegExp = /[a-zA-z]+/;

var inputString = "www.dailycoding.com";

var myMatches = document.frm1.txt1.value.match(myRegExp);

for(var i=0; i

{

alert(myMatches[i]);

}

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.