/    Sign up×
Community /Pin to ProfileBookmark

number/text validation in javascript

Hi,
I’ve created a text box. I want that, if any any one type less then 7 character/numbers, then an alert box will be appeared-“Incorrect Number”. For that, I type these codes:
<form name=f1, action=”” value=post>
<input type =textbox, name=t1 onSubmit= “return val(true)”>
</form>

function vai(){
if(f1.t1.value.length < 7){
alert(“Incorrect Number”);
return false;
}
}

But, it’s not working. also no error are showing.
So, what’s wrong?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorFeb 14.2008 — [B]onsubmit[/B] belongs to the [B]form[/B] element, not to the input element. And: all the elements belong to the [B]document [/B]object. Also, be consistent and nest all the attributes value inside double quotes
<i>
</i>&lt;form name=[COLOR="Blue"]"[/COLOR]f1[COLOR="Blue"]"[/COLOR], action="" value=[COLOR="Blue"]"[/COLOR]post[COLOR="Blue"]"[/COLOR] [COLOR="Blue"]onsubmit="return val()"[/COLOR]&gt;
...

<i>
</i>function vai(){
if([COLOR="Blue"]document[/COLOR].f1.t1.value.length &lt; 7){
alert("Incorrect Number");
return false;
}
}
×

Success!

Help @akaki 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

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