Good call.
Here are my changes.
function validate_phone(value,alerttxt){
var re = /^\(\d{3}\)\d{3}-\d{4}$/;
alert(re);
if( $('input[name=unitContactPhoneNumber]').fieldValue().match(/^\(\d
{3}\)\d{3}-\d{4}$/) ){
alert('match');
return true;
}
else{
alert(alerttxt);
return false;
}
}
But when I check, the alert(re) fires but the other 'alerts' do not.
It's like the .match() is not called.
John
On Jun 12, 9:48 am, Michael Lawson <[email protected]> wrote:
> Maybe I'm reading this wrong, but the regular expression you are using
> looks like it returns a match on valid phone numbers? If that is the case
> why not
> return true when it matches, false when it doesn't. Ir just put a ! in
> front of the match function
>
> cheers
>
> Michael Lawson
> Development Lead, Global Solutions, ibm.com
> Phone: 1-276-206-8393
> E-mail: [email protected]
>
> 'Examine my teachings critically, as a gold assayer would test gold. If you
> find they make sense, conform to your experience, and don't harm yourself
> or others, only then should you accept them.'
>
> From: John <[email protected]>
>
>
> To: "jQuery (English)" <[email protected]>
>
>
> Date: 06/12/2009 09:38 AM
>
>
> Subject: [jQuery] Regular Expressions and jQuery
>
>
> Hello all,
> I have some experience in Regular Expressions but this one has me
> pulling my hair out.
>
> I have a form with several input fields including a phone number
> field. I have a submit button that is linked to jquery form plugin.
> My validation is checked on "beforeSubmit". ( i.e. beforeSubmit:
> validateForm )
> I've used validateForm() for other simple validation via javascript.
> This time I'm using jQuery Form which shouldn't be and isn't a
> problem. My issue is in the validation of phone number.
>
> Within validateForm is this...
>
> function validateForm(formData, jqForm, options) {
>
> var queryString = $.param(formData);
> alert(queryString);
>
> // VALIDATE ENTIRE FORM
> //phone
> if (validate_phone($('input
> [name=piResults]').fieldValue(), "Please
> enter a valid phone number.") == false){
> phoneNum.focus();
> return false;
> }
>
> }
>
> // VALIDATE PHONE NUMBER
> function validate_phone(value,alerttxt){
>
> var re = /^\(\d{3}\)\d{3}-\d{4}$/;
>
> if( value.match(/^\(\d{3}\)\d{3}-\d{4}$/) ){
> return false;
> }
> else{
> return true;
> }
>
> }
>
> When validate_phone is called, the parameter "value" is correct. The
> problem is the "match" is not checked.
> Is there another way?
>
> Thanks for any help.
>
> J Mcleod
>
> graycol.gif
> < 1KViewDownload
>
> ecblank.gif
> < 1KViewDownload