I believe this is what you are looking for:
function UserName_TextChanged(which) {
if (/[^a-zA-Z]/gi.test(which.value)) {
alert ("Only alpha characters are valid in this field"); // no spaces, full stops or anything but A-Z
which.value = "";
which.focus();
return false;
}
}
I don't have Hebrew on my machine, but I believe it will stop those characters as well
You call this method like so:
ontextchanged="UserName_TextChanged(this)"
Explanation of code:
function UserName_TextChanged(which) {
The "which" variable is the control you are validating. Notice when you call the function, you pass "this", which loosely translates to "this object"
if (/[^a-zA-Z]/gi.test(which.value)) {
This tests a regex pattern against the value of the control you passed in
alert ("Only alpha characters are valid in this field");
If the pattern matches (meaning there are characters other than a-z), you are alerting the user that they entered invalid characters
which.value = "";
Here you are erasing the control's text. You might not want to do this, depending on your needs.
which.focus();
Here you are putting the cursor back into the control you are validating.
return false;
This is used in case you are calling this validation before submitting a form. By returning false, you can cancel the submission of the form.