So i have this project where i need to write a mutator method that changes a person's phone number only if the phone number contains numbers from 0 to 9 and no letters or any other things. The type of the phone number is string and i tried using conditional statements. If the mobile contains anything other than numbers then nothing should happen. this is what i got so far:
public void setMobile(String mobile) {
if(mobile.matches("[a-zA-z]+")){
}
else{
this.mobile = mobile;
}
}
thanks