OZONE Asylum
Forums
DHTML/Javascript
telephone number input
This page's ID:
31987
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
hi all. I'm having some trouble and was hoping someone might be able to help me out. I've been using php and mysql for a long time, and I always used server side validation, but I never really looked at JS much. Getting back into web design for the first time in a while, I've decided to try JS for client-side validation. I have found a few examples, and have started working on a more advanced contact form. I'm making progress, but I've hit a hitch. the javascript I have so far is - [code] function validate_phone(current, destination) { current.value=current.value.replace(/[^\d]/,''); if (current.getAttribute&¤t.value.length == current.getAttribute("maxlength")){ destination.focus(); destination.select(); } } [/code] and the html - [code] <input type="text" id="areaCode" size="2" maxlength="3" onkeyup="validate_phone(this, document.contact.prefix);"> <label>) </label> <input type="text" id="prefix" size="2" maxlength="3" onkeyup="validate_phone(this, document.contact.suffix);"> <label>-</label> <input type="text" id="suffix" size="3" maxlength="4" onkeyup="validate_phone(this, document.contact.body);"> [/code] it works as intended going forward, but the problem I'm having is if you enter a wrong number, editing a full input box becomes tricky. I'm not sure how to handle this. any insight would be great. also, if anyone knows a good resource for regular expressions in javascript I'd love to see it. regex has always been a mystery to me, but I know it will be useful when validating input. [edit] edited for overflow; [url=www.IXIfx.net][img]http://www.IXIfx.net/asylum/sigs/Guitar.gif[/img][/url] [sigrotate] Of all the things I've lost, I miss my mind the most (Ozzy Osbourne)| Some people say I'm a dreamer, but I'm not the only one (John Lennon)| Life is too short, so love the one you got (Bradley Nowell)| I focus on the pain; The only thing that's real (Trent Reznor)| I know the pieces fit, 'cause I watched them fall away (Maynard J. Keenan)| Take your time, hurry up; the choice is yours just don't be late (Kurt Cobain)| You could stand me up at the gates of hell, but I won't back down (Tom Petty)| Do you serve a purpose or purposely serve (Corey Taylor)| You know I'd like to keep my cheeks dry today, so stay with me and I'll have it made (Shannon Hoon) [/sigrotate] [small](Edited by [url=http://www.ozoneasylum.com/user/4616]I X I[/url] on 09-17-2010 22:43)[/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »