I'm trying to validate a textbox to see if it contains numbers and special characters, but for some reason, my code doesn't seem to work:
<script> function validation(){ var firstname = $("#Fname").val(); if(firstname.match(/^[A-Za-z]*/)){ return true; } else{ alert("Invalid name!"); return false; } }; </script> And here is where I called the function:
<form method="POST" action="confirmReservation.php" onSubmit="return validation()" name ="frm"> <div class="col-md-2 form-group"> <br><input type="text" id = "Fname" name="Fname" class="form-control" placeholder="First Name" required> </div> </form> What might be the problem in my code?
$to ensure a full string check:/^[A-Za-z]*$/.$is not yielding expected behavior, please provide a full fiddle to help you better.