/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Assistance with regular expressions

I want to make a regular expression test an employee id number when they enter it into a prompt. The format is as follows

AXXXXXX

each X represents a number from 0 – 9. The first character, “A” is a constant and is the only string character the user can input (can be lowercase or uppercase A). I want it to test this particular pattern and return a message if the user does not type it properly. I know how to do all the valdation stuff, but am confused on how to create the regular expression to test this.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@mark_yiehNov 09.2006 — if (/^(a|A)[0-9]{6}$/.test(formFieldValue)) {

alert("value is acceptable");

} else {

alert ("value is not acceptable");

}
Copy linkTweet thisAlerts:
@UltimaterNov 09.2006 — If the first character MUST be an "A" or "a":
<i>
</i>alert(/^[aA]d{6}$/.test("A370015"))

If the first character can be any letter a,b,c...z or A,B,C...Z:
<i>
</i>alert(/^[a-zA-Z]d{6}$/.test("D479213"))
Copy linkTweet thisAlerts:
@daniboi81authorNov 10.2006 — Worked like a charm...Thanks a bunch
×

Success!

Help @daniboi81 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.19,
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,
)...