澳大利亚电话号码验证 [英] Australian Phone Number Validation

查看:111
本文介绍了澳大利亚电话号码验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个只能接受澳大利亚有效电话号码的网络表单。
我有 data-type =phone,但是<不承认澳大利亚数字格式。
我试图编辑 parsley.js 文件没有成功。有没有人有代码接受澳大利亚数字格式?
如果没有,我怎么能让电话号码字段成为一个必需的数字字段,它也接受空格和最少8位数字? data-typedigit似乎不允许有任何空格。

I have a web form that should only accept valid Australian phone numbers. I have data-type="phone" on the phone field though the parsley.js file does not recognize Australian number formats. I have attempted to edit the parsley.js file without any success. Does anyone have the code to accept Australian number formats? Failing that, how could I make the phone number field a required digit field that also accepts spaces and a minimum of 8 digits? data-type"digit" doesn't seem to allow any spaces.

推荐答案

如果你想用所有的HTML5浏览这个小提琴: http://jsfiddle.net/bud68oho / 2 /

If you want want to go with all HTML5 look at this fiddle: http://jsfiddle.net/bud68oho/2/

这个小提琴使用所需的 code>属性来验证表单。 必需属性不允许表单在输入未填写时发布。模式属性允许您实现匹配的正则表达式。如果输入不符合正则表达式的要求,那么表单将不会发布。

This fiddle uses the required and pattern attributes to validate the form. The required attribute does not allow the form to post if the input is not filled in. The pattern attribute allows you to implement regex for matching. If the input does not meet the requirements of the regex then the form will not post.

这种方法唯一的问题是浏览器兼容性。确保使用目标浏览器测试此方法。上面的例子适用于最新版本的IE和Chrome,我无法做任何进一步的测试。

The only gotcha with this approach is browser compatibility. Make sure to test this method with your target browsers. The above example works in the latest version of IE and Chrome, I am unable to do any further testing.

这篇关于澳大利亚电话号码验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆