こんにちは、az、AZ、0-9、-、&、_ などのフォーム フィールドでユーザーが特定の文字のみを使用できるようにしたいと考えています。
私は正規表現が苦手です。jqueryを使用して文字列にこれらの文字以外が含まれているかどうかを確認する正規表現関数は何ですか
\w文字、数字、アンダースコアは次のように使用できます。
^[\w&-]+$
これだけ
  ^[A-Za-z0-9\-_&]+$
^ Start of string
Char class [A-Za-z0-9\-\_] 1 to infinite times [greedy] matches:
    A-Z A character range between Literal A and Literal Z
    a-z A character range between Literal a and Literal z
    0-9 A character range between Literal 0 and Literal 9
    \-_& One of the following characters -_&
$ End of string
あるいは  ^[\w\d\-_&]+$
^ Start of string
Char class [\w\d\-\_] 1 to infinite times [greedy] matches:
    \w Word character [a-zA-Z_\d]
    \d Digit [0-9]
    \-_& One of the following characters -_&
$ End of string
あなたはこれを行うことができます:
function isValid(str) {
    return (/^[a-zA-Z0-9_\-&]+$/gi).test(str);
}
次のようにテストします。
console.log(isValid('aA0_-&'));   // true
console.log(isValid('test*'));    // false