how should i prevent the users to input special characters? ihave these codes :
function registerDialog(){
var message = '';
if(loginBox != ''){
$.modal.close();
}
var html =
'<div>'
+'<h4 style="background:#DADEE7;padding:10px;border:1px solid #ccc;"><i class="fa fa-chevron-circle-right "></i> Register</h4>'
+'<input type="email" id="emailBox" placeholder="Email Address" style="width:90%; margin:10px auto 3px 10px;"/>'
+'<input type="password" id="passwordBox" placeholder="Password" style="width:90%; margin:10px auto 3px 10px;"/>'
+'<input type="text" id="realNameBox" style="width:90%;margin:10px auto 10px 10px;" placeholder="Complete Name."style="width:90%; margin:10px auto 3px 10px;" onkeypress="return restrictCharacters(this, event, alphaOnly);" />'
+'<p id="infoBox" style="width:90%;margin-left:10px;margin-bottom:5px;"></p>'
+'<p id="infoBox2" style="width:90%;margin-left:10px;margin-bottom:5px;"></p>'
+'<p style="text-align:right;">'
+'<button style="padding:5px;margin-right:5px;" id="signUpBtn">Submit</button>'
+'<button style="padding:5px;margin-right:20px;" id="cancelBtn">Cancel</button>'
+'</p>'
+'</div>'
registerBox = $.modal(html, {
closeHTML:"",
containerCss:{
backgroundColor:"#fff",
borderColor:"#fff",
minHeight: 250,
width: ($(window).width() > 320)? 320 : $(window).width() - 10,
padding:0
},
overlayClose:true,
opacity:80,
overlayCss: {
backgroundColor:"#000"
},
onShow : function (dialog) {
$("#signUpBtn",dialog.data).click(function(){
var email = $('#emailBox').val();
var passwordBox = $('#passwordBox').val();
var realNameBox = $('#realNameBox').val();
if(email != '' && passwordBox != '' && realNameBox != '' && validateEmail(email) && filterName(realNameBox)){
$.ajax({
type : 'get',
async : false,
url: baseUrl+'/Index/register',
data:{
email : email,
password: passwordBox,
realname: realNameBox
},
error: function(req,error){
console.log(req.statusText);
},
dataType: 'json',
cache: false,
success : function(msg){
if(msg.status == "OK"){
message = 'Successfully Registered.';
alert(message);
window.location.reload();
}else{
message = 'Registration failed, Email address already used.';
$('#infoBox').html(message).css('color', 'red');
return false;
}
}
});
}else{
if(email == ''){$('#emailBox').addClass('border-red');}else{$('#emailBox').removeClass('border-red');}
if(passwordBox == ''){$('#passwordBox').addClass('border-red');}else{$('#passwordBox').removeClass('border-red');}
if(realNameBox == ''){$('#realNameBox').addClass('border-red');}else{$('#realNameBox').removeClass('border-red');}
$('#infoBox').html('Please complete or correct the fields above marked in red.');
if(validateEmail(email) == false){
$('#emailBox').addClass('border-red');
}else{
$('#emailBox').removeClass('border-red');
}
return false;
}
});
$('#realNameBox').keypress(function(e){
if (e.which == 13) {
$("#signUpBtn",dialog.data).click();
}
});
$("#cancelBtn",dialog.data).click(function(){
var email = $('#emailBox').val('');
var passwordBox = $('#passwordBox').val('');
$.modal.close();
});
},
onOpen: function (dialog) {
dialog.overlay.fadeIn('fast', function () {
dialog.data.hide();
dialog.container.fadeIn('fast', function () {
dialog.data.slideDown('fast');
});
});
},
onClose: function (dialog) {
dialog.data.fadeOut('fast', function () {
dialog.overlay.slideUp('fast', function () {
$.modal.close();
});
});
}
});
}
i tried putting some code to restrict the text box from accepting the special characters but it seems like it's not working. thanks in advance! God Bless