/    Sign up×
Community /Pin to ProfileBookmark

A minor problem with a check for number and "/"

This is the code I have so far:

if (!(frm.fld1.value.search (/^[0-9]{6,10}$/) > -1)) {
alert(“Please Enter a Valid Date – 12/12/2006”);
frm.fld1.focus();
return false;
}

It check for numbers only. How do I make sure it’ll check for the “/” sign as well?

Thanks!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@felgallJul 21.2006 — the following check for / - or . separators as well as validating a day between 1 and 31, month between 1 and 12 and year between 1900 and 2099. Leading zeros on day and month are optional.

day month year

/^(0?[1-9]|[12][0-9]|3[01])[/.- ](0?[1-9]|1[0-2])[/.- ](19|20)d{2}$/

month day year

/^(0?[1-9]|1[0-2])[/.- ](0?[1-9]|[12][0-9]|3[01])[/.- ](19|20)d{2}$/

year month day

/^(19|20)d{2}[/.- ](0?[1-9]|1[0-2])[/.- ](0?[1-9]|[12][0-9]|3[01])$/
Copy linkTweet thisAlerts:
@CharlesJul 21.2006 — Here's a more robust way of doing things. Instead of being so rigid and unforgiving with your user we help him or her out:<script type="text/javascript">
Date.prototype.toDateString = function () {return [this.getMonth() < 9 ? '0' + (this.getMonth() + 1) : this.getMonth() + 1, this.getDate() < 10 ? '0' + this.getDate() : this.getDate(), this.getFullYear()].join('/')}
</script>

<label>Date <input onchange="var d = new Date (this.value); if (isNaN (d)) {alert (''); this.value = ''; this.focus()} else {this.value = d.toDateString()}"></label>
Copy linkTweet thisAlerts:
@weeeauthorJul 21.2006 — Thanks guys!
×

Success!

Help @weee spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...