0

I'm validating a form where a user either fills in his phone number or e-mailadres. But at least one of the two needs to be filled in.

I'm using this validation plugin: http://www.geektantra.com/projects/jquery-form-validate/advanced_demo/

I think it should look something like this, but that doesn't seem to work:

    expression: "if ((VAL) || jQuery('#email').val()) return true; else return false;",

Hoping for help.

1

1 Answer 1

-1

If you are trying to validate for phone or email,

Try using this,

   expression:  if ((VAL.match(/^[0-9]*$/) && VAL.length == 10) || VAL.match(/^[^\\W][a-zA-Z0-9\\_\\-\\.]+([a-zA-Z0-9\\_\\-\\.]+)*\\@[a-zA-Z0-9_]+(\\.[a-zA-Z0-9_]+)*\\.[a-zA-Z]{2,4}$/)) return true; else return false;

This actually checks if its a phone number or email and if any one of it is valid then, it returns true.

Try something like this if you are having 2 input fields,

jQuery(this).parents("form").submit(function(){
var isFormValid = true;
    if(SelfID != <PHONE FEILD> || SelfID != <EMAIL FEILD> ){
        if (validate_field('#' + SelfID)) 

        else 
            isFormValid =  false;
    }
    if(validate_field('#' + <PHONE FEILD>)  || validate_field('#' + <EMAIL FEILD>)){
        if(isFormValid ==  true){
            return true;
        }else{
            return false;
        }
    }
});
2
  • Thanks for your answer! I´m talking about two input fields here (not one). One of the two needs to be filled in at least. Either the phone number-field or the email-field. Apr 18, 2013 at 9:12
  • In that case, while submitting the form you exclude your Phone field and email field and validate the form and then from these two fields check if any one of them are valid.
    – sivanv
    Apr 19, 2013 at 9:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.