0

trying to create a matcher for finding if title is not correct i.e. has to be mr, mrs, miss etc..but this allows mrmrmr etc when it should not. tried different setups to keep failing i.e. [[]] or ().

public void valTitle(){
    //validate title
    while (this.title.matches("^[\\s]+$")
                                    ||this.title.matches("")
                                    ||this.title.matches("[^m]&&[^r]*")
                                    ){
                                System.out.println("Title can not"
                                        + " be empty or have spaces, must contain "
                                        + "a-z characters and has to be correct "
                                        + "length in size i.e. Mr or Miss");
                                System.out.println("Enter your title ?");
                                 title = inputDetails.nextLine();
        }
    }
2
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by andyhunter
0

You could use (Mr|Mrs|Miss){1} , but really equalsIgnoreCase() could be used just as well for those three specific cases.

0

thats great but the problem is that i need it not to equal (Mr|Mrs|Miss){1} i.e. with characters [^m] but i dont think != works with this type of regex ?

0

thank you very much, i was about to give up.I did not know that could be used :O.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.