mardi 22 décembre 2015

Check the Strings unavailability in a sentence Android

Public void function() {
if(n.length()<3 || n.length()>50){
        alertBeforeSave("Check Name");
        b=false;
    }
    else if(e.lastIndexOf("@")>0 && e.lastIndexOf(".co")>0 || e.lastIndexOf(".com")>0 || 
            e.lastIndexOf(".edu")>0 || e.lastIndexOf(".info")>0 || e.lastIndexOf(".in")>0 ||
            e.length()>5 || e.length()>50 || e.lastIndexOf("@@")>0 || e.lastIndexOf("@.")>0 ||
            e.lastIndexOf(".@")>0){
        b=false;
        alertBeforeSave("Check Email");
    }
    else if(mcc.lastIndexOf("+91")>0){
        if(m1.length()<10 || Integer.parseInt(m1)<700000000){
            alertBeforeSave("Check Mobile Number");
            b=false;
        }
        else
            b=true;
    }
    else if(mcc.lastIndexOf("+91")<0){
        if(mcc.length()<1 || m1.length()<3 && Integer.parseInt(m1)<1999){
            alertBeforeSave("Check Mobile Number");
            b=false;
            //failed to check code is zero
        }
        else{               
            b=true;
        }
    }       

    if(Integer.parseInt(td)<50 || !b){
        Toast.makeText(getApplicationContext(),"Check Bike Details", Toast.LENGTH_LONG).show();
        Log.d("Days or Validation Wrong", td);
        return 0;
    }
    else
        return 1;
}

In this the first else if statement always true if it contains (@,.co,...)

else if(e.lastIndexOf("@")>0 && e.lastIndexOf(".co")>0 || e.lastIndexOf(".com")>0 || 
            e.lastIndexOf(".edu")>0 || e.lastIndexOf(".info")>0 || e.lastIndexOf(".in")>0 ||
            e.length()>5 || e.length()>50 || e.lastIndexOf("@@")>0 || e.lastIndexOf("@.")>0 ||
            e.lastIndexOf(".@")>0)

But I need to do reverse. If no such string I need to enter inside that loop. If exists go for the next

The second condition has faults also I need to fix that later. But I want If the string not exists in the sentence, I need to go inside.

Aucun commentaire:

Enregistrer un commentaire