My below mentioned code still submits form on special character in name field. Validation works but If I submit repeatedly it breaks and submits the form with special chars in name.
What could be the reason for this?
$("#fee").submit(function(){
trimmedValue = $.trim($("#name").val());
$("#name").val(trimmedValue);
typevalue = $("input:radio[@name='type']:radio:checked").val();
if(typevalue=="FLAT" && !isFloat($("#amount").val())) {
alert("Amount should be number with proper decimal formatting");
$("#amount").val("0.0");
return false;
}
var noSpecialChars = /[^a-zA-Z0-9]/g;
if (noSpecialChars.test($("#name").val())) {
alert("Please enter valid fee Name. Do not enter special characters" );
return false;
}
if(typevalue=="PERCENTAGE" && !isFloat($("#percentage").val())) {
alert("percentage should be number with proper decimal formatting");
$("#percentage").val("0.0");
return false;
}
if(typevalue=="FLAT" && $("#amount").val()=="0.0") {
return confirm("Do you really want the amount to be 0.0 ?");
}
if(typevalue=="PERCENTAGE" && $("#percentage").val()=="0.0") {
return confirm("Do you really want the percentage to be 0.0 ?");
}
});