-3
我有下面的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,@, (空白区域)以外的任何内容。 (点),_和 - ,这是你想要的吗? –