Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
157
rated 0 times [  161] [ 4]  / answers: 1 / hits: 98608  / 10 Years ago, wed, july 16, 2014, 12:00:00

This is my html:



 <input type=text name=folderName>


Here, I want to validate the textbox value by not allowing to key in special characters and space. But it should allow underscore.



How to validate this textbox?


More From » html

 Answers
54

You may try to use this function:



<html xmlns=http://www.w3.org/1999/xhtml>
<head id=Head1 runat=server>
<title></title>
<script type=text/javascript>
function blockSpecialChar(e){
var k;
document.all ? k = e.keyCode : k = e.which;
return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 32 || (k >= 48 && k <= 57));
}
</script>
</head>
<body>
<form id=frm runat=server>
<input type=text name=folderName onkeypress=return blockSpecialChar(event)/>
</form>
</body>
</html>

[#70189] Monday, July 14, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rylee

Total Points: 658
Total Questions: 114
Total Answers: 116

Location: Christmas Island
Member since Mon, Oct 19, 2020
4 Years ago
;