Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
「p」は、「$」、コンマ、ドット、または数字のみを格納できます。
他の文字が含まれている場合、アラートを表示するにはどうすればよいですか?
if (p.match(/[^$,.\d]/)) alert('error!');
ライブデモ
この 優れた正規表現のチートシートを使用できます。
検討:
if (/[^$,\.\d]/.test(p)) { // value has characters other than $ , . 0-9. };
正規表現のテストメソッドはブール値を返しますが、matchは配列を返すため、同様の方法で使用する場合は型変換に依存します。