I have written a validation for accepting numbers and special characters but it is accepting only numbers while validating not accepting special characters.
$(document).ready(function () { $("#law_degree_academic_years").keypress(function (e) { if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) { $("#errmsg").html("Digits Only").show().fadeOut("slow"); return false; } }); }); <div class="form-group"> <label for="law_degree_academic_years" class="col-sm-2 control-label">41. Law Degree Academic Years</label> <div class="col-sm-9"> <input type="text" class="form-control" value="<?php echo $oppointArr['law_degree_academic_years'];?>" name="law_degree_academic_years" id="law_degree_academic_years" placeholder="Ex:2017-2020" minlegth="9" maxlength="9" required> </div> </div>
Try this method
function Validate() { var isValid = false; var regex = /^[0-9-+()]*$/; isValid = regex.test(document.getElementById("TextBox1").value); return isValid; }
1.4m articles
1.4m replys
5 comments
56.9k users