/    Sign up×
Community /Pin to ProfileBookmark

phone validation does not recognize correct entry

This is urgent — my client’s form is not working live. I am no coder, but someone who is unavailable at the moment wrote the script below. When the correct phone number format is entered, it still returns, “Please enter a valid phone number”. My search cannot find a specific solution because I am not smart enough with the js. Can you see the problem and suggest how I can quickly fix it?

[B]Validation Script[/B]:

// function to check US phone – format 999-999-9999
function IsPhone(snum)
{
var rePhone = /^(d{3})(-)(d{3})(-)(d{4})$/
return rePhone.test(snum)
}

[B]Inline script in php page:[/B]

<input style=”font-family: Arial,Helvetica,sans-serif; font-size: 11px;” maxlength=”80″ id=”phone” size=”23″ name=”phone” value=”Day Time Phone Number” onFocus=”this.value=”;return false;” type=”text”>

[B]Reference URL: http:freemovefreemoney.com[/B]
Index page form, right side of window

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@LeeUJan 10.2007 — Try this and see if it works:
[CODE]var rePhone = /^(?[2-9]d{2}[).-]?s?d{3}[s.-]?d{4}$/
return rePhone.test(snum)[/CODE]
Copy linkTweet thisAlerts:
@JackAndrewsauthorJan 10.2007 — Thanks but I have no idea how or where to paste this --- head? --- inline? -- inside } and }? --- in the script in place of what's there now or in the page? Sorry to be so green on this.
Copy linkTweet thisAlerts:
@Arty_EffemJan 10.2007 — This is urgent -- my client's form is not working live. I am no coder, but someone who is unavailable at the moment wrote the script below. When the correct phone number format is entered, it still returns, "Please enter a valid phone number". My search cannot find a specific solution because I am not smart enough with the js. Can you see the problem and suggest how I can quickly fix it?

[B]Validation Script[/B]:

// function to check US phone - format 999-999-9999

function IsPhone(snum)

{

var rePhone = /^(d{3})(-)(d{3})(-)(d{4})$/

return rePhone.test(snum)

}

[B]Inline script in php page:[/B]

<input style="font-family: Arial,Helvetica,sans-serif; font-size: 11px;" maxlength="80" id="phone" size="23" name="phone" value="Day Time Phone Number" onFocus="this.value='';return false;" type="text">

[B]Reference URL: http:freemovefreemoney.com[/B]

Index page form, right side of window[/QUOTE]


The error is coming from the function isInt, which fails to validate anything but digits. Change the expression in that function to read:

/^(d|-)+$/
Copy linkTweet thisAlerts:
@JackAndrewsauthorJan 10.2007 — Do you mean here?

// function to check indiger field

function IsInteger(snum)

{

var reInteger = /^d+$/

return reInteger.test(snum)

or in the code I sent originally?
Copy linkTweet thisAlerts:
@JackAndrewsauthorJan 10.2007 — It worked!! in the IsInteger function ---- a gillion thanks!! I've spent all day trying to figure this out.
×

Success!

Help @JackAndrews 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.12,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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