-3
Javaを使用して電話番号を検証しようとしています。文字列が正しい長さ(10桁)であることを確認する方法を教えてください。do/whileでJavaの電話番号をどのように検証しますか?
do{
System.out.println("Please provide the phone number starting with area code: ");
this.phone = input.nextLine();
} while (!phone.matches("[0-9]"));
正規表現を使用する場合は、なぜですか?while(!\ d {10} ");' – dave
https://docs.oracle.com/javase/tutorial/essential /regex/quant.html – Tom
@daveは正しくありますが、 '\ d'は間違っています。 '\\ d'にする必要があります。 – Tom