js RegExp bug All In One
js RegExp bug All In One
translated bug
// OK && tranlate `/`
let new_obj_reg = new RegExp(`^(([^<>()\\[\\]\\.,;:\\s@\\"]+(\\.[^<>()\\[\\]\\.,;:\\s@\\"]+)*)|(\\".+\\"))@(([^<>()[\\]\\.,;:\\s@\\"]+\\.)+[^<>()[\\]\\.,;:\\s@\\"]{2,})$`);
// /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/
new_obj_reg.test(`admin@xgqfrms.xyz`);
// true
// Error && not tranlate `/`
let obj_reg = new RegExp(`^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$`);
// /^(([^<>()[].,;:s@"]+(.[^<>()[].,;:s@"]+)*)|(".+"))@(([^<>()[].,;:s@"]+.)+[^<>()[].,;:s@"]{2,})$/
obj_reg.test(`admin@xgqfrms.xyz`);
// false
let reg = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/;
// /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/
reg.test(`admin@xgqfrms.xyz`);
// true
// reg.test(`"admin@xgqfrms.xyz"`);
// false
console.log(`reg =\n`, reg);
console.log(`obj_reg =\n`, obj_reg);
console.log(`new_obj_reg =\n`, new_obj_reg);
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
var regex1 = /\w+/;
let regex2 = new RegExp('\\w+');
console.log(regex1);
// expected output: /\w+/
console.log(regex2);
// expected output: /\w+/
console.log(regex1 === regex2);
// expected output: false
console.log({} === {});
// false
转译
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#Description
// 转译 `\` && OK
let new_obj_reg = new RegExp(`^(([^<>()\\[\\]\\.,;:\\s@\\"]+(\\.[^<>()\\[\\]\\.,;:\\s@\\"]+)*)|(\\".+\\"))@(([^<>()[\\]\\.,;:\\s@\\"]+\\.)+[^<>()[\\]\\.,;:\\s@\\"]{2,})$`);
// /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/
new_obj_reg.test(`admin@xgqfrms.xyz`);
// true
// 未转译 `\` && Error
let obj_reg = new RegExp(`^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$`);
// /^(([^<>()[].,;:s@"]+(.[^<>()[].,;:s@"]+)*)|(".+"))@(([^<>()[].,;:s@"]+.)+[^<>()[].,;:s@"]{2,})$/
obj_reg.test(`admin@xgqfrms.xyz`);
// false
let reg = /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/;
// /^(([^<>()\[\]\.,;:\s@\"]+(\.[^<>()\[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/
reg.test(`admin@xgqfrms.xyz`);
// true
// reg.test(`"admin@xgqfrms.xyz"`);
// false
flags
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags
vue & form validation
password & re-sure password
// rules
{
passWord: [
{
required: true,
message: "请输入密码",
trigger: "change",
},
{
min: 3,
max: 20,
message: "长度在 3 到 20 个字符",
trigger: "blur",
}
],
passWordSure: [
{
required: true,
message: "请输入密码",
trigger: "change",
},
{
min: 3,
max: 20,
pattern: `^${this.$data.form.passWord}$`,
// pattern: `${this.$data.form.passWordSure}`,
message: "两次输入的密码不一致",
trigger: "blur",
}
],
}
ChildNode.remove()
https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove
refs
©xgqfrms 2012-2020
www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/10024396.html
未经授权禁止转载,违者必究!