Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Limit phone # field to exactly 10 digits
Old 11-19-2006, 02:14 AM Limit phone # field to exactly 10 digits
Junior Talker

Posts: 3
Trades: 0
I'm trying to restrict the phone # to exactly 10 digits using the below JS

Form.phone.value = form.phone.value.replace(/[^0-9]/g,"");
if (!form.phone.value){
alert ("Please fill in a PHONE NUMBER." );
return false;
}
and have played around with variations of
...replace(/([(^0-9)]{10})$/g,"");
and
...replace(/^(0-9){10}/g,"");
with no luck. Could someone offer advice on how to get this done?
I think {10} is the correct syntax, but 'where' it goes in the statement is stumpin' me.
I can adapt the code to match the other fields.
Thank you.
TokyoJ

Last edited by TokyoJ; 11-19-2006 at 02:16 AM..
TokyoJ is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-19-2006, 02:24 PM Re: Limit phone # field to exactly 10 digits
logic ali's Avatar
Super Talker

Posts: 104
Trades: 0
Quote:
Originally Posted by TokyoJ View Post
I'm trying to restrict the phone # to exactly 10 digits using the below JS

Form.phone.value = form.phone.value.replace(/[^0-9]/g,"");
if (!form.phone.value){
alert ("Please fill in a PHONE NUMBER." );
return false;
}
and have played around with variations of
...replace(/([(^0-9)]{10})$/g,"");
and
...replace(/^(0-9){10}/g,"");
with no luck. Could someone offer advice on how to get this done?
I think {10} is the correct syntax, but 'where' it goes in the statement is stumpin' me.
I can adapt the code to match the other fields.
Thank you.
TokyoJ
Do it in two stages. The first as you have already, then replace everything following the first 10 digits:

Form.phone.value=Form.phone.value.replace(/[^\d]/g,"").replace(/^(\d{10}).*$/,"$1");
logic ali is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Limit phone # field to exactly 10 digits
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10721 seconds with 12 queries