I have a Javascript function like this:
function validateSessionName() {
var session_name = document.getElementById('session_name').value;
var submitButton = document.getElementById('submit');
document.getElementById('session_error').innerHTML='';
submitButton.removeAttribute('disabled');
var filter = /^[A-Za-z0-9]+$/;
if (filter.test(session_name)){
return true;
} else {
document.getElementById('session_error').innerHTML="Invalid Session Name!";
submitButton.setAttribute('disabled', 'disabled');
}
}
This validates that only numbers and alphanumerical characters are entered into the form. However, there might be a case when a session name can consist of !@$#$#(%*. All these characters are available on the keyboard. I don't want my application to accept these weird characters: 工具, which make my application crash. How can I do that? Thanks.