2012-12-12 124 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