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
565 views
in Technique[技术] by (71.8m points)

html - how can I set a max value on my html5 date input so that it could be recognized by safari for iOS?

The title is pretty clear I guess?

Here's my date input :

<input type="date" id="birthdate" name="birthdate" value="" max="1993-12-07" required/>

In chrome, I cannot enter a date superior to 1993-12-07 using the little arrows of the field (but if I write the date myself I can).

In safari for iOS, focusing that field just brings a nice datepicker. However, this datepicker is NOT limited to the "max" attribute. So how can I do that? Of course, I have a server-side form validation but I want to make it on client-side too. Any idea? Thanks!

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Safari does not yet support it yet . Only Opera and chrome support it as of Nov 2011. Anyways here is the w3spec on it http://www.w3.org/TR/html-markup/input.date.html#input.date.attrs.max

You can use js validation on submit or on change. Use a js validation framework of your choice

Here is pure js example http://www.roseindia.net/answers/viewqa/Ajax/4734-start-date-and-end-date-validation-in-javascript.html. Use your max date instead of end date

For jquery solution look at this Validate that end date is greater than start date with jQuery


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

...