$("#btnSubmit").click(function () { //validate mobile var phone = $("#txtContactNumber").val(); if (!validatePhone(phone)) { alert('Invalid Contact Number'); $("#txtContactNumber").focus(); return; } alert('Form submitted'); }); function validatePhone(phoneText) { var filter = /^[0-9-+]+$/; if (filter.test(phoneText)) { return true; } else { return false; } }
<input id="txtContactNumber" type="text" /> <br /><br /> <input id="btnSubmit" type="submit" value="submit" />