/    Sign up×
Community /Pin to ProfileBookmark

Javascript RegExp in Forms

I cannot get the result right. I write area and phone by numbers but it still gives me error

[code]
function validate_text(field,alerttext) {
with(field) {

var re = /[a-zA-Z]/g;
if(re.test(field)) { return true;}else{alert(alerttext);return false;}
}
}
function validate_number(field,alerttext){
with(field) {

var re = /[0-9]/g;
if(re.test(field)) { return true;}else{alert(alerttext);return false;}
}
}

function validateForm(thisForm){
with(thisForm)
{
if(validate_number(area,”wrong area code”) == false) {

area.focus();return false;
}
if(validate_number(phone,”wrong phone”) == false) {

phone.focus();return false;
}
if(validate_text(name_surname,”wrong name”) == false) {

name_surname.focus();return false;
}

}
}[/code]

[code]…<b>Name Surname :</b><input style=”margin-left:10px;” type=”text” name=”name_surname”/>
<br /><br />
<b>phone :</b><input type=”text” style=”margin-left:19px;” maxlength=”4″ size=”4″ name=”area” />
-<input type=”text” style=”margin-left:5px;” maxlength=”7″ size=”10″ name=”phone” /><br /><br />….[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@FangAug 26.2010 — [CODE]function validate_number(field,alerttext){
var re = /[0-9][COLOR="Blue"]{4}[/COLOR]/;
if(re.test(field[COLOR="Blue"].value[/COLOR])) { return true;}else{alert(alerttext);return false;}
}
[/CODE]
×

Success!

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