Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text or Number type accept into the Input box

Status
Not open for further replies.

ibike

Programmer
Apr 7, 2003
27
0
0
IT
Hello,

Can somebody tell me which kind of style what I can use for my input if I would like to accept only text or number type for my input field?

Thank you in advance!
 
You will need to use a "Regular Expression" in Javascript if you want to validate a field in this way. It will check that the string entered conforms to a specific rule, such as it contains only letters [a-z] or the numbers [0-9].

They are powerful, but the syntax can be tricky at first.

e.g. To test that the "entrantName" field contains only numbers and letters:
Code:
var nameTest = /^[a-z 0-9]+$/i;

function isValid(pattern, str) {
	return pattern.test(str);
}


if (!isValid(nameTest, document.all.entrantName.value))
{
	return false;
};
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top