$(function(){ var phoneCheck = function (elem, isFocus){ var elemName = elem.attr("name"), form = elem.parents("form"), value = $.trim(elem.val()); if (isFocus && elem.is(":invalid")){ return false; } if (elemName!="phone"){ var phoneElem = $("[name=phone]", form), phoneValue = phoneElem.val(); if (phoneValue==phonePrefix || phoneValue.length0 && !/\d+/.test(e.key)){ return false; } return true; }); });