1.必須包含大小寫數字 8-16位
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z0-9]{8,16}$/複製程式碼
2.數字千分位展示
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}複製程式碼
3.轉義需要轉義的
function escapeRegexp(queryToEscape) {
return queryToEscape.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1')
}複製程式碼
4. 連字元轉駝峰 ad-bd-cd to adBdCd
var camelizeRE = /-(\w)/g;
var camelize = function (str) {
return str.replace(camelizeRE, function (_, c) {
return c ? c.toUpperCase() : '';
})
}複製程式碼
5.駝峰轉連字元
var hyphenateRE = /\B([A-Z])/g;
var hyphenate = function (str) {
return str.replace(hyphenateRE, '-$1').toLowerCase()
};複製程式碼
6.轉義html
function htmlEscape(text){
return text.replace(/[<>"&]/g, function(match, pos, originalText){
console.log(match, pos, originalText)
switch(match){
case "<": return "<";
case ">":return ">";
case "&":return "&";
case "\"":return """;
}
});
}複製程式碼
7.判斷相對 絕對路徑
var absolutePath = /^(?:\/|(?:[A-Za-z]:)?[\\|/])/;
var relativePath = /^\.?\.\//;
function isAbsolute(path$$1) {
return absolutePath.test(path$$1);
}
function isRelative(path$$1) {
return relativePath.test(path$$1);
}
複製程式碼