-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,@, (空白區域)以外的任何內容。 (點),_和 - ,這是你想要的嗎? –