初めて正規表現を使用していて、本当に驚きました!まあ、新しい発見は常に驚き:)。 JavaScriptで使用しています。私は方法を以下で使用しています。(そこに多くのフィールドがあり、すべてはこの電話の書式を除いて完全に正常に動作している)正規表現の問題:カスタム電話番号の書式設定
function validate(form) {
var phone = form.phone.value;
var phoneRegex = /^(\+|00)\d{2,3}-\d{1,2}-\d{3}-\d{4}$/g;
//Checking 'phone' and its regular expressions
if(phone == "") {
inlineMsg('phone','<strong>Error</strong><br />You must enter phone number.',2);
return false;
}
if(!phone.match(deptRegex)) {
inlineMsg('phone','<strong>Error</strong><br />Enter valid phone <br />+xxx-x-xxx-xxxx (or) <br />00xxx-x-xxx-xxxx.',2);
return false;
}
return true;
}
今HTML
<div id="wrapper">
<form name="form" id="form" class="form" onsubmit="validate(this);return false">
<label for="phone">Phone:</label><input type="text" name="phone" id="phone" />
<input type="submit" value="Submit" class="submit" />
</div>
私は私が間違って書いたかもしれないことを混同しています私はそれをテストしました。私はJavaScriptで表現を書くのは間違いだと思います。助けてもらえますか?
p.s以下は、私が式を試験したregular expression online testerの画像です。
あなたの質問を少し詳しく説明できますか? –
問題はなんですか?正規表現を使用するコードは何ですか? –
あなたの正規表現は動作します:http://regexr.com?30me1あなたの問題はおそらく他の場所です。 – Sampson