In my gridview, one of the columns contains a Text Box Control.
I am looking to validate the text entered by users as alphanumeric characters and spaces only.
Allowed characters are: a-z, A-Z, 0-9, and space.
I want to perform this validation using JavaScript.
Platform: ASP.Net 2.0, C#
Here is what I have attempted so far...
<script type="text/javascript">
function IsValidCharNum(event) {
var KeyBoardCode = (event.which) ? event.which : event.keyCode;
if ((KeyBoardCode < 96 || KeyBoardCode > 123) && (KeyBoardCode < 65 || KeyBoardCode > 90) && (KeyBoardCode < 48 || KeyBoardCode > 57) && (KeyBoardCode !== 32)) {
return false;
}
return true;
} </script>
When used with onkeypress="return IsValidCharNum(event)" for a textbox outside of the gridview and update panel, it works as expected.