Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
850 views
in Technique[技术] by (71.8m points)

javascript - Australian Phone Number Validation

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

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.

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...