<template>
<a-form-model-item ref="password" prop="password">
<a-input-password
placeholder="请输入登录密码"
v-model="cusForm.password"
/>
</a-form-model-item>
</template>
<script>
export default {
data() {
// 密码输入校验
var checkPwd = (rule, value, callback) => {
//xss攻击特殊字符过滤
let arr = [
"alert",
"eval",
"script",
"<script>",
"<\/script>",
"onblur",
"onload",
"onfocus",
"onerror",
"onclick",
"onMouseOver",
"onMouseOut",
"onSelect",
"onChange",
"onSubmit",
"console",
"href",
"<iframe>",
"</iframe>",
"<img>",
"</img>",
"<iframe>",
"</iframe>",
"<video>",
"</video>",
"<canvas>",
"</canvas>",
"<label>",
"</label>",
"<span>",
"</span>",
"document",
"location",
"javascript",
];
//遍历数组 验证数组中的每一项是否存在于输入的字符串里。
for (let i = 0; i < arr.length; i++) {
//方法可返回某个指定的字符串值在字符串中首次出现的位置
if (value.indexOf(arr[i]) != -1) {//判断条件是否成立
this.cusForm.password = "";
return callback("请输入正确的格式密码");
}
}
callback();
};
return {
cusForm: {
password: "",
},
cusRules:{
password: [
{
required: true,
message: "请输入登录密码",
trigger: "blur",
},
{
min: 5,
max: 20,
message: "密码长度应为5-20位",
trigger: "blur",
},
{ validator: checkPwd, trigger: ["blur", "change"] },
],
}
}
}
</script>
密码框限制xxs注入字符处理
于 2023-01-18 15:07:54 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)