Domanda

i have cellphone text filed i given default value some text.

that text field is not required but if the user enters the number it should check for elven digits

my problem is that this field is asking for validation

text filed code

     var cellnotextfield = Titanium.UI.createTextField({
    //borderStyle : Ti.UI.INPUT_BORDERSTYLE_ROUNDED,
    value : 'Cellphone Number',
    backgroundColor : '#32302D',
    color : 'white',
    //backgroundImage : 'none',
    keyboardToolbarHeight : 30,
    borderRadius : '7%',
    paddingLeft : 10,
    width : '98%',
    height : '20%',
    top : '4%',

    //backgroundColor:'green'
});


 and validation code
       if (namesurnametextfield.value == '' || namesurnametextfield.value =='Name & Surname*' ) {
        alert("Please enter the name or surname");
        return;
        //isvalid=false;
    } else if (!namesurnametextfield.value.match(/^[a-zA-Z ]*$/)) {
        alert('Please enter only alphabets');
        isvalid = false;
        return;
        //return 0;
    } else if (emailtextfield.value == '' || emailtextfield.value =='Email Address*') {
        alert('Please enter  your email');
        return;
        //return 0;
    } else if (!emailtextfield.value.match(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/)) {
        alert('Please enter valid email');
        return;
        //return 0;
    } else if (cellnotextfield.value == '' || cellnotextfield.value =='Cellphone Number') {

        alert("dont do any thing");
    }else if (!cellnotextfield.value.match(/^\d{11}$/)) {

            alert('Please enter only elven eigits');

        }
     else if (displaynametextfield.value == '' || displaynametextfield.value =='Display Name*') {
        alert('Please enter display name');
        return;
        //return 0;
    } else if (!displaynametextfield.value.match(/^[a-zA-Z]+$/)) {
        alert('Please enter only alphabets');
        return;
        //return 0;
    }
È stato utile?

Soluzione

The problem is that you enter the validation inside the condition while it should be a else if :

else if (!(cellnotextfield.value == '' || cellnotextfield.value =='Cellphone Number') && !cellnotextfield.value.match(/^\d{11}$/)) {

    alert('Please enter only elven eigits');
    return;
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top