必须检查长度,并在文本框中允许一些特殊字符

Have to check length and allow some special character in a textbox

本文关键字:文本 特殊字符 许一些 检查      更新时间:2023-09-26

有一个文本框必须检查长度,我必须只允许一些特殊的字符

function checkPasswordLength(thisValue) {
    var regexp1 = new RegExp("(www|http|https|WWW|HTTP|HTTPS)");
    var regexp2 = /^[a-zA-Z0-9 !@#$%&*]$/i;
    if ((thisValue.length<8)||(!regexp2.test(thisValue.value))||regexp1.test(thisValue.value)) {
        modal({
            type: 'warning',
            title: 'Warning',
            text: 'Password must contain at least eight characters!!<br/>Special Character such as (:<>,.~`(){};/") are not allowed',
            center: false,
            callback: function () { $(thisValue).focus(); }
        });
        exit;
        return false;
    }
    return true;
}

这是小提琴。

如果必须查找URL,可以使用reg exp

var urlRexp = /^(http:'/'/www'.|https:'/'/www'.|http:'/'/|https:'/'/)[a-z0-9]+(['-'.]{1}[a-z0-9]+)*'.[a-z]{2,5}(:[0-9]{1,5})?('/.*)?$/i

此外,您的代码需要一些更改

 if ((thisValue.length<8)|| ... 

应更改为

   if ((thisValue.value.length<8)||

在你的JS文件夹中,不要在OnLoad中加载代码。将其更改为"无换行"选项。

如果你想使用你自己的正则表达式,你可以签出RegExp101链接,看看你的代码是如何工作的。它是一个在线regexp测试程序。

希望这对你有帮助。