2012-12-12 126 views
1

荫工作jQuery验证..需要jQuery验证

荫面临着手机验证和荫不了解如何添加如下另一个验证问题:

下面是荫实现的:

- telephone number in all UK formats (4 digit area code, a space, 7 digit local code), The 'telephone' number field (4 digit area code, a space, 7 digit local code) 

- visitor location from a drop-down list which includes the items: South Yorkshire, Rest of England, Wales, Scotland, Northern Ireland, European Union, Rest of World, Other, and which includes an appropriate default, 


。请查收我的代码在这里:http://jsfiddle.net/B5sd8/18/

回答

0

为什么不使用Masked Input like this?看演示,我很确定你可以格式化你的面具,以适应你在世界上需要的任何电话号码。

0

您可能会对现有的网络服务感兴趣,例如GeoNames,它们允许您搜索地址(或简单的国家)进行检查。

我会强烈建议使用jQuery validate而不是重新发明轮子

一个快速谷歌搜索与JQuery验证英国的电话号码原来这件事

filters

,看起来像这样

jQuery.validator.addMethod('phoneUK', function(phone_number, element) { 
    return this.optional(element) || phone_number.length > 9 && 
    phone_number.match(/^(\(?(0|\+44)[1-9]{1}\d{1,4}?\)?\s?\d{3,4}\s?\d{3,4})$/); 
    }, 'Please specify a valid phone number' 
); 
+0

请问您可以告诉我在哪里添加此方法? – Clarsen