อยากได้วิธีดักไม่ให้กรอกขระพิเศษ ช่อง user กับ pass ครับ >.<
Code (JavaScript)
<script type="text/javascript">
$(document).ready(function(){
var numberRegex = /^[+-]?\d+(\.\d+)?([eE][+-]?\d+)?$/;
$('#form1').validate({
rules: {
txtusername: {required:true,minlength:4,remote: "checkuser.php"},
txtpass:{required:true,minlength:4, },
txtcpass:{required: true, equalTo: "#pass", minlength: 4},
txtcode:{required:true,minlength:4},
txtnameagent:{required:true,minlength:4},
txtname:{required:true,minlength:4},
txtlname:{required:true,minlength:4},
txtaddress:{required:true,minlength:10},
txttel:{required:true,minlength:7},
txtfax:{required:true,minlength:7},
txtemail:{required:true,email:true},
txtweb:{required:true,url:true},
txtlogo:{ required: true, accept: "png|jpe?g|gif", filesize: 1048576 },
},
messages:{
txtusername: {required: "Please enter a username",
minlength: "Your username must consist of at least 4 characters",regex: "ห้ามใส่อักระพิเศษ",
remote: jQuery.format("{0} is already in use")},
txtpass: {required:"Please fill ",
minlength:"At least 4 ",regex: "ห้ามใส่อักระพิเศษ"},
txtcpass:{required:"Please fill ",equalTo:"Please fill same password"},
txtcode:{required:"Please fill",minlength:"At least 4"},
txtnameagent:{required:"Please fill",minlenght:"At least 4"},
txtname:{required:"Please fill",minlength:"At least 4"},
txtlname:{required:"Please fill",minlength:"At least 4"},
txtaddress:{required:"Please fill",minlength:"At least 10"},
txttel:{required:"Please fill",minlength:"At least 7"},
txtfax:{required:"Please fill",minlength:"At least 7"},
txtemail:{required:"Please fill ",email:"Please email only"},
txtweb:{required:"Please fill",url:"Please url web only"},
txtlogo:{required:"Please fill ",accept:"File must be JPG, GIF or PNG, less than 1MB"},
}
});
// check even click this button
$('#button').click(function(){
if($('#form1').valid())
{
var url = 'registersave.php';
var params = $('#form1').serialize();
$.post(url,params,callback_reserv);
$("#register").fadeOut('fast', function(){
$('#results').html(data);
});
}
});
function callback_reserv(data)
{
if(data.indexOf('OK')!=-1)
{
alert('Register Complete');
window.location='index.php';
}
else
alert(data);
}
});
</script>