/    Sign up×
Community /Pin to ProfileBookmark

code requested please

hi all,

i am very new to this site!…

i would really appreciate it if some1 can help me with the js code for this….?….

i have a text field for which the input mask shld be of the format xx-xxxx-xxxx-x . the first 2 chars could be alpha but the rest shld only be numeric. this text field shld also be able to handle the delete, backspace keys appropriately…

thanks much in advance….

to post a comment
JavaScript

7 Comments(s)

Copy linkTweet thisAlerts:
@suganyaauthorJun 30.2003 — i do not find any code similar to what i need...any help wud definitely be appreciated.....

thankyou
Copy linkTweet thisAlerts:
@CharlesJun 30.2003 — [font=monospace]<input type="text" onchange="if(!/^w{2}-d{4}-d{4}-d$/.test(this.value)) {alert('That does not appear to be a valid entry.'); this.value=''; this.focus()}">[/font]
Copy linkTweet thisAlerts:
@pyroJun 30.2003 — Try something like this:

&lt;html&gt;
&lt;head&gt;

&lt;script type="text/javascript"&gt;
function validate(frm) {
re = /^w{2}[-](d{4}[-]){2}d{2}$/;
if (!re.test(frm.mytext.value)) {
alert ("That is an invalid entry");
}
}
&lt;/script&gt;

&lt;/head&gt;

&lt;body&gt;
&lt;form name="form1" method="post" action="" onsubmit="return validate(this);"&gt;
&lt;input type="text" name="mytext"&gt;(ie. xx-1111-1111-11)
&lt;input type="submit" value="Submit"&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@pyroJun 30.2003 — Charles -

Your's doesn't allow for two digits at the end of the string.

Did you mean this:

(!/^w{2}-d{4}-d{4}-d{2}$/.test(this.value)
Copy linkTweet thisAlerts:
@CharlesJun 30.2003 — [font=georgia]Admittedly my eyes are bad and getting worse, but the way I read the request only one trailing digit is required. But just to be sure I'm going to brew up a pot of tippy gold Yunan. That always helps.[/font]
Copy linkTweet thisAlerts:
@pyroJun 30.2003 — lol... know what? It's not you, it's me... :rolleyes: You were right. One digit at the end...
Copy linkTweet thisAlerts:
@suganyaauthorJun 30.2003 — thanks very much charles and pyro...
×

Success!

Help @suganya 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.18,
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,
)...