/    Sign up×
Community /Pin to ProfileBookmark

certain character, plus amount of characters required

I am very new to JavaScript.

I have a form which asks this question:

“Enter your student ID #: ” <input type=”text”….etc

I need a function which requires a total of 9 characters, and it must begin with the letter ‘L’. There should simply be an alert message which states the correct format if the user does not enter it correctly.

Can anyone help me out?

I can read and understand a lot of JavaScript, but am not proficient in it at all.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Aug 06.2008 — You can use a regexp. You should check on the server too though.

/^L.{8}$/

Something like<i>
</i>&lt;input type="text" onblur="if (!/^L.{8}$/.test(this.value)) alert('YOUR MESSAGE HERE');"&gt;
Copy linkTweet thisAlerts:
@Marshmellow_ManauthorAug 06.2008 — That was a great suggestion and it works.

Could you tell me a way to do something similar. A number is required for another field, and it must be less than 30.

Dan
Copy linkTweet thisAlerts:
@Declan1991Aug 06.2008 — if (isNaN(this.value) || Number(this.value) < 0 || Number(this.value > 30))
×

Success!

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

Tweet This
about: ({
version: 0.1.9 BETA 6.1,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...