LSW Posted October 8, 2012 Report Share Posted October 8, 2012 Finally on the requesting help side of things again... I am updating a classic ASP app & one of the requests was for auto formatting of the phone number. Now the first upgrade was to add validation which I did with Regular Expressions and it worked fine: .Pattern = "^\([1-9]\d{2}\)\s?\d{3}\-\d{4}{:content:}quot; Now they want auto formatting which is used the JavaScript from Kodyaz. This has validation in it, so I had commented out the regular Expression. But what I end up with is the formatting working fine, but not the validation, so if no area code is given, the first 3 numbers land in the area code, then 3 more, the dash and the last number: (465) 114-3 I have been messing around with both trying to get the JS to require all 10 digits or the regular expression to flag the error and neither work. So does anyone have a suggestion on how to tweak the formatting section to require 10 numbers? Full code is at the above link, the validation part is: var maxphonelength = 14; function ValidatePhone(object){ var p = phonevalue1 p = p.replace(/[^\d]*/gi,"") if (p.length < 3) { object.value=p } else if(p.length==3){ pp=p; d4=p.indexOf('(') d5=p.indexOf(')') if(d4==-1){ pp="("+pp; } if(d5==-1){ pp=pp+")"; } object.value = pp; } else if(p.length>3 && p.length < 7){ p ="(" + p; l30=p.length; p30=p.substring(0,4); p30=p30+") " p31=p.substring(4,l30); pp=p30+p31; object.value = pp; } else if(p.length >= 7){ p ="(" + p; l30=p.length; p30=p.substring(0,4); p30=p30+") " p31=p.substring(4,l30); pp=p30+p31; l40 = pp.length; p40 = pp.substring(0,9); p40 = p40 + "-" p41 = pp.substring(9,l40); ppp = p40 + p41; object.value = ppp.substring(0, maxphonelength); } I have tried to cut it down as I really do not see the use of if / else. either it is (XXX) 465-1143 or an error message asking for the area code. PS - I am on the clock with this as I discovered it when I moved it to the test server and we have to get people testing it this week, so any help is appreciated. Quote Link to comment Share on other sites More sharing options...
LSW Posted October 9, 2012 Author Report Share Posted October 9, 2012 No one? Where are all our JavaScript people? At least this got put on the side burner for a few days. Quote Link to comment Share on other sites More sharing options...
LSW Posted October 12, 2012 Author Report Share Posted October 12, 2012 Can't really say what the issue was as it started working all of a sudden. Anyways I had the above JavaScript and then used the phoneValue1 is a validation using Regular Expressions. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.