私は以下の3つの機能を持っています。 私はあなたが何かを「防ぐ」ために正規表現を書いていない右正規表現 は私にJavascript特殊文字を禁止する正規表現
//Allow Alphanumeric,dot,dash,underscore but prevent special character and space
function Usernames(txtName) {
if (txtName.value != '' && txtName.value.match(/^[0-9a-zA-Z.-_]+$/) == null) {
txtName.value = txtName.value.replace(/[\W- ]/g, '');
}
}
//Allow Alphanumeric,dot,dash,underscore and space but prevent special characters
function Fullnames(txtName) {
if (txtName.value != '' && txtName.value.match(/^[a-zA-Z0-9. -_]+$/) == null) {
txtName.value = txtName.value.replace(/[\W-]/g, '');
}
}
//Allow Alphanumeric,dot,dash,underscore the "@" sign but prevent special character and space
function Email(txtName) {
if (txtName.value != '' && txtName.value.match(/^[[email protected]]+$/) == null) {
txtName.value = txtName.value.replace(/[\W-]/g, '');
}
}
問題がありますか?それらのすべてで? – DontVoteMeDown
「特殊文字」は正確には何ですか?例えばなぜ '@'は特殊文字ではなく '&'ですか? – Liam
'[^ a-zA-Z0-9 \ @ \ s \。\ _ \ - ]'は、a-z、A-Z、0-9、@、 (空白) (ドット)、_と - 、これはあなたが望むものですか? –