/    Sign up×
Community /Pin to ProfileBookmark

Form Validation not working. Pls help.

Hi:

I have a form input field that need to be validated with at least 5 character and must contain one letter and 1 number. But it is not working. Below is my code. Please help. Thank you.

[CODE]
<form id=”search_mini_form” action=”/catalogsearch/result/” method=”get” target=”frame1″>
<div class=”form-search”><label for=”search”>Search:</label>
<input id=”search” class=”input-text” type=”text” name=”q” value=”” />
<button class=”button” title=”Search” type=”submit” ><span><span>Search</span></span></button>

<script type=”text/javascript”>
<!–
function checkserial(){
var reg = /^.*(?=.{4,10})(?=.*d)(?=.*[a-zA-Z]).*$/i //regular expression defining a 5 digit number
if (document.search_mini_form.q.value.test(reg)==-1) //if match failed
alert(“Please enter a valid serial number.”)
}
–>
</script>

</form>
[/CODE]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@PadonakJun 14.2012 — try this one

[CODE]... if (!reg.test(document.search_mini_form.q.value)) ...[/CODE]
×

Success!

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