📜  expression régulière téléphone java 代码示例

📅  最后修改于: 2022-03-11 14:52:41.613000             🧑  作者: Mango

代码示例1
// verifie le format d'un String de numero de telephone et ajuste le format
// Format possible : xxxxxxxxxx || xxx xxxxxxx || xxxxxx xxxx || xxx xxx xxxx
// xxx-xxxxxxx || xxxxxx-xxxx || xxx-xxx xxxx || xxx xxx-xxxx || xxx-xxx-xxxx
// (xxxxxxxxxx || xxx)xxxxxxx || (xxx xxxxxxx || xxx) xxxxxxx || (xxx-xxxxxxx
// etc.
// Format final : (xxx)xxx-xxxx
if(numero.matches("\(?(\d{3})\)?[- ]?(\d{3})[- ]?(\d{4})")){
    newNumero = numero.replaceFirst("\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})", "($1)$2-$3");
}