₦airaland Forum

Welcome, Guest: Register • Login • With Google • Trending • Recent • New

Stats: 3,347,676 members, 8,528,777 topics. Date: Wednesday, 02 December 2026 at 09:53 PM

Toggle theme

Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input - Webmasters (2) - Nairaland

Nairaland Forum › Science/Technology › Webmasters › Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input (4178 Views)

1 2 3 Reply (Go Down)

Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by Nobody: 10:55am On Sep 30, 2013
@OP

I guess u berra download the w3schools offline version.. Just open 4shared.com and search for "W3schools offline version".. Its about 26mb.. Download n extract.. Once extracted, it should be around 112mb..

Its quite handy and saves u further internet costs logging in n out of the site.. Plus all the tutorials are inside.. With The tests and all..

Cheers..
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by wisemania(op): 11:09am On Sep 30, 2013
dhtml: Let me try to explain this code a bit more. This is a shorthand code that means
evt = (evt) ? evt : window.event;

if (evt) {evt=evt;} else {evt=window.event;}
it also meants
if (evt=true) {evt=evt;} else {evt=window.event;}

The way events work on microsoft internet explorer and other browsers is slightly different. This code bridges that gap.

But if you are using jQuery and all them them library, you do not need to bother yourself with crossplatform issues.
boss u 4got 2 include a button 2ur post,coz i juz noticed it on my browsers output....i beg du well 2 include it,ill be waiting sha,make i c weda i fit try include am....
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by wisemania(op): 11:13am On Sep 30, 2013
Djangocode: @OP

I guess u berra download the w3schools offline version.. Just open 4shared.com and search for "W3schools offline version".. Its about 26mb.. Download n extract.. Once extracted, it should be around 112mb..

Its quite handy and saves u further internet costs logging in n out of the site.. Plus all the tutorials are inside.. With The tests and all..

Cheers..
thanks bro,bt me no kon get dat hand full of internet bundle....any how sha,..since u call ur code killer u fit drop a tin or 2 4ur boi as regards d issue on ground...no b sin sha
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by wisemania(op): 11:25am On Sep 30, 2013
dhtml: Are you sure i have accomplished it? You may want to do your own version, oya, make we hear your explanation. Me no sabi explain at all at all. . . .even me sef no understand my own explaining and explanations. . .
boss,ibeg dat ur code no complete atall,u for no sleep typ naw,anywaz i try am again..u didnt add a prompt 2 b displayed if d user inputs a right or wrong number,a button 2 activate d script,...plsssss restructure d code again,i mst understand diz tin 2dae,by fire by water...thanks
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by dhtml(m): 4:13pm On Sep 30, 2013
wisemania: boss,ibeg dat ur code no complete atall,u for no sleep typ naw,anywaz i try am again..u didnt add a prompt 2 b displayed if d user inputs a right or wrong number,a button 2 activate d script,...plsssss restructure d code again,i mst understand diz tin 2dae,by fire by water...thanks
My code does not need a button, and it is complete. My code makes sure only numbers are entered into the phone field, of you try entering rubbish, it will not accept it, plain and simple. The script watches your keyboard as you are typing. You never see this kind code before?
And oncontextmenu has been since html4, but most developers except maybe oldies like me know it and use it.
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by dhtml(m): 4:21pm On Sep 30, 2013
If you want to add a button, you can add submit button, but my script does not need button to validate. The only thing is that you may be looking at form validation to prevent empty phone number field from getting submitted. But my code makes sure you only enter valid phone number. If you want to prevent someone from using Ctrl + v to paste, I can show u how to block that.

By the way, I use unobtrusive style of coding.
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by wisemania(op): 6:11pm On Sep 30, 2013
dhtml: My code does not need a button, and it is complete. My code makes sure only numbers are entered into the phone field, of you try entering rubbish, it will not accept it, plain and simple. The script watches your keyboard as you are typing. You never see this kind code before?
And oncontextmenu has been since html4, but most developers except maybe oldies like me know it and use it.
k......no vex sir,i b tink say u 4get ni,accept my regrets.ibeg show me hw 2 blok sm1 4rm usin "ctrl+v".make i try am again...thanks
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by dhtml(m): 8:26pm On Sep 30, 2013
I no vex nao, my own style of coding is old-skul,
http://pastebin.com/DwqsKNYb
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by CODEEATER(m): 8:27pm On Sep 30, 2013
dhtml: I no vex nao, my own style of coding is old-skul,
http://pastebin.com/DwqsKNYb
lol...old school indeed..

Hw fa na...wats next
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by dhtml(m): 8:36pm On Sep 30, 2013
^^^Your own corrected and working code with explanations - and it must work crossplatform
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by wisemania(op): 9:17pm On Sep 30, 2013
[quote author=CODE-EATER]lol...old school indeed..

Hw fa na...wats next[/quote]4yur mynd.make i kon dey beg u 4 codes abi..No b ur fault naw.
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by CODEEATER(m): 9:40pm On Sep 30, 2013
wisemania: 4yur mynd.make i kon dey beg u 4 codes abi..No b ur fault naw.
No o...a beg o...no think go dat side o...

No vex a beg,2day get as e b 4 me
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by wisemania(op): 9:53pm On Sep 30, 2013
dhtml: ^^^Your own corrected and working code with explanations - and it must work crossplatform
boss 2b frank wif u,ive neva bin diz confused and fustrated in my entire LIFE,i just upgraded d codes u gave me again wif d "ctrl+v" tin,yet d script did not prevent me 4rm entering special xters and letters...i don tire.Even d mst simplest number validation codes i got online dey fail me...i juz tire 4 all dis tinz o....i beg give me a veeeeeeeeery simple numba val code,make i try am ....b4 i vex smash my system 4 wall....@code-eater i stil dey xpect ur own sha
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by dhtml(m): 3:12am On Oct 01, 2013
Which browser did you test it inside? This is an online link of what i gave you - http://.net/demos/phone.html - and it does not accept numbers.
Maybe you should upload the script you wrote online so we can see it - i cannot help you debug what i cant see - my code is working well no doubt.
But i must warn you that if you make a single mistake inside javascript, the code will fail - even if the mistake is from another script. So let us have a public link so we can see the problem.
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by wisemania(op): 8:38am On Oct 01, 2013
dhtml: Which browser did you test it inside? This is an online link of what i gave you - http://.net/demos/phone.html - and it does not accept numbers.
Maybe you should upload the script you wrote online so we can see it - i cannot help you debug what i cant see - my code is working well no doubt.
But i must warn you that if you make a single mistake inside javascript, the code will fail - even if the mistake is from another script. So let us have a public link so we can see the problem.
k...i used torch,firefox and navigator browsers..2 test dem....ill upload d codes 4u 2 c den..
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by CODEEATER(m): 9:39am On Oct 01, 2013
dhtml: Which browser did you test it inside? This is an online link of what i gave you - http://.net/demos/phone.html - and it does not accept numbers.
Maybe you should upload the script you wrote online so we can see it - i cannot help you debug what i cant see - my code is working well no doubt.
But i must warn you that if you make a single mistake inside javascript, the code will fail - even if the mistake is from another script. So let us have a public link so we can see the problem.
This guys code rocks...it dsnt recognise anything oda Dan numbers...


Did u use HTML5 number input type?
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by wisemania(op): 12:05pm On Oct 01, 2013
dhtml: Which browser did you test it inside? This is an online link of what i gave you - http://.net/demos/phone.html - and it does not accept numbers.
Maybe you should upload the script you wrote online so we can see it - i cannot help you debug what i cant see - my code is working well no doubt.
But i must warn you that if you make a single mistake inside javascript, the code will fail - even if the mistake is from another script. So let us have a public link so we can see the problem.
dis is it

<!DOCTYPE html>
<html>
<head>
<title>Phone Validation</title>
<script>
function isCtrl(evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if(charCode==17) {alert("Access denied"wink;}
}
function isPhone(el,evt) {
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode > 31 && (charCode < 48 || charCode > 57)) {
return false;
}
if(el.value.length==3||el.value.length==7||el.value.length==13) {el.value=el.value+"-";}
return true;
}
</script>
</head>
<body>
<p id="para">please Enter your phone number and press the button to test its validity:</p>

<form action="javascript:alert('Please put script to submit to');">
<input type="text" id="phone" onkeypress="return isPhone(this,event)" oncontextmenu="return false" onkeydown="return isCtrl(event)"/>

<input type="submit" value="Submit"/>
</form>
</body>
</html>
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by wisemania(op): 12:15pm On Oct 01, 2013
[quote author=CODE-EATER]This guys code rocks...it dsnt recognise anything oda Dan numbers...


Did u use HTML5 number input type?[/quote]broda as u don get am now me don dey vex,he kon b like say i no sabi my abc and 123 again sha...did u use d exact code above? Coz i used d same yet i waz able 2 input letters,special xters,etc in d input space...i saw a normal popup alert box askin me2 "please put script to submit to",wc script du i put again,i changed d action to "#" on submitin d script it disapeared in 2 tin air...wetin u du wey d script recognize only "numbers"?
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by wisemania(op): 12:31pm On Oct 01, 2013
dhtml: Which browser did you test it inside? This is an online link of what i gave you - http://.net/demos/phone.html - and it does not accept numbers.
Maybe you should upload the script you wrote online so we can see it - i cannot help you debug what i cant see - my code is working well no doubt.
But i must warn you that if you make a single mistake inside javascript, the code will fail - even if the mistake is from another script. So let us have a public link so we can see the problem.
Ese BABAMI.....d code finally gave me d desired output..d mistake wz on my part...i used "$$" in place of "&&" in d "if" conditional operator ..thanks, bt a js alert box is alwaz popin up wen er i submit d form,it does not show d "access denied" alert wen er i input numbers of length 17,y boss?
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by dhtml(m): 5:18pm On Oct 01, 2013
I used ordinary html4, no html5.
change the submit code
replace <form action="javascript:alert('Please put script to submit to');">
with
<form action="submit.php">
that is what is popping up when u are trying to submit.

i told you how to limit the maximum length in an earlier code - maxlength attribute in the button form.
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by wisemania(op): 5:37pm On Oct 01, 2013
dhtml: I used ordinary html4, no html5.
change the submit code
replace <form action="javascript:alert('Please put script to submit to');">
with
<form action="submit.php">
that is what is popping up when u are trying to submit.

i told you how to limit the maximum length in an earlier code - maxlength attribute in the button form.
k thanks..i kw how 2 include "d maxlength" bt i wnt 2 b a lil bit flexible,i wnt d script 2 alert d "access denied" u included in d script wen a user inputs a 17 digit number...
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by dhtml(m): 5:46pm On Oct 01, 2013
That does not make sense to me, the smart thing to do is to prevent rubbish from being entered.
So if user enters 17 characters, it pops up message to reduce? why not prevent from getting beyond what you want?
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by wisemania(op): 6:13pm On Oct 01, 2013
dhtml: That does not make sense to me, the smart thing to do is to prevent rubbish from being entered.
So if user enters 17 characters, it pops up message to reduce? why not prevent from getting beyond what you want?
ok sir,i guess ill av 2 acept wt my oga @ d top sayz...thanks alot..happy independence!
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by dhtml(m): 10:41pm On Oct 01, 2013
You are welcome. Mister Spambot is the oga at the top.
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by CODEEATER(m): 10:58pm On Oct 01, 2013
Dhtml...u sabi nodejs?


Need some briefing tuts on it
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by wisemania(op):
Thanks 2 ya'll wu made me understood d basics of jscript..ive finally gotten a hand full of ideas 2 validate wt xo eva i wish 2 validate ,am xtremely obliged ...once again i say a BIGY THANKZ...avin writen n executed various forms containg just one input 4d user, i tot it wise n brave 2 increase d num of inputs 4d user 2 fill and submit.But 2my greatest dismay,all d single forms dat haz bin running oldiz yl suddenly bakame xooo lame 2 even walk...4 instance i created a form askin d user 2 fill his name,email add,paswrd,phone-num,etc...bt al 2 no effect except i run dem in saparate files...i den decided 2 allocate each file 2 a specific function on d xame script yet a negative outcome,i used diff scripts yet 2 no desired result....i kw sm1 outder knowz hw 2 go about it..i use diz medium 2 crave ur(/webmasters+/) indulgence 2 asist me in getting all d inputs in a single script....thanks in anticipation....oya make d codes dey boil in chapaly,myblood dey sima.....
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by dhtml(m): 2:14am On Oct 02, 2013
[quote author=CODE-EATER]Dhtml...u sabi nodejs?


Need some briefing tuts on it[/quote]Yes I Sabin node, express and phone gap, but those things are hard to teach small, I don resign from writing tutorials these days, no time.

Putting a whole form together and validating is not so easy, my advise is to post the link to the form online and let people validate and contribute.
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by CODEEATER(m): 6:07am On Oct 02, 2013
@wise...validate the whole form how,me no really get u...


@dhtml...just a brief run through of the concept n syntax.. n maybe a basic example.. abeg
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by wisemania(op): 9:13am On Oct 02, 2013
<!DOCTYPE html>
<html>
<head>
<script>
var pmail=/[a-z0-9_.-]+@[a-z]+\.[a-z]{2,5}/i;

var pass=/^[a-z0-9.#*-]+{8,10}$/i;

function validate(){
if(!pmail.test(document.getElementById("email"wink.value)
{alert("Enter a valid Email!"wink; return false;
}
if(!pass.test(document.getElementById("pswrd"wink.value)
{alert("Enter a valid password"wink; return false;}
return true;
}
</script>
</head>

<body>
<form id="myform" method="get">
Enter Email:
<input type="text" id="email" maxlength="30" size="45" required/>
<input type="submit" value="check" onclick="validate()"><br><br>

Enter password:
<input type="text" id="pswrd" maxlength="10" size="45" required/>
<input type="submit" value="validate" onclick="validate()"><br>

<input type="submit" value="Submit Form" onclick="validate()"/>

</form>
</body>
</html>

wen er i run d code abv,n i input a non-valid email an alert box will appear tell me 2 enter a valid email..but if i enter an invalid password it will stil ask me 2 input a valid email,meaning d email err is overiding d password's...ill like 2 c a modification of my code such dat,wen i input an INVALID EMAIL
and am about 2 proceed 2d nxt input an ALERT BOX shud appear tell me my errs(or beta stil u kud prefare 2use d "check" button beside d inputs 2 validate it),without alowin me 2 proceed 2d nxt until i correct my mistake....it sounds easy "bt me no kon kw am sha"....i kw som gurus on diz forum cn hlp me out.....am patiently waitin....thanks in advance
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by dhtml(m): 6:26pm On Oct 02, 2013
Me don tire small to dey write javascript o. Let us have another volunteer
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by wisemania(op): 8:24pm On Oct 02, 2013
dhtml: Me don tire small to dey write javascript o. Let us have another volunteer
is there no other js guru in diz rum dat cn hlp wif dis "simple" code..... Or r der no webmasters on diz forum anymor....ya'll shud prove me rung...i nid dis codes like now....
Re: Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input by dhtml(m): 2:58am On Oct 03, 2013
@op, i think the problem is that you need to learn javascript and increase your html knowlege especially in the area of forms. Normally, i only like writing codes to assist, but to start writing like an entire project is stressful for me. Even that code i wrote sef, i sure say you know understand how to manipulate am at all.
Form validation codes full internet like anything, but to use them, you need to improve on your knowlege of HTML, form element names, IDs and some basic javascript usage.
In case you do not realize it, javascript is far more complex and tougher than PHP, this is the reason why many people (even some good web developers) run away from writing javascript codes. Most people rely on jQuery and other libraries except those that have been javascript gurus before these them jQuery libraries exist.
I love keeping my application size small, so i only use all them libraries when absolutely needed - i dont feature them in over 70% of my projects.
1 2 3 Reply

Urgently Need Some To Validate My Form • How To Validate HTML5 Forms On All Browsers • How To Validate Your Html Or Xhtml Pages / Websites • 2 • 3 • 4

How Do I Start Accepting Credit Card Payments On My Site? • My Request When Elvis10ten Is Cleared • Blog Content Writer Available