国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

vue+element項目中過濾輸入框特殊字符小結

2019-11-19 11:04:03
字體:
來源:轉載
供稿:網友

 可以在main.js中寫入方法

 Vue.prototype.validSe = function (value, number = 255) {value = value.replace(/[`~*~!@#$%^&*()_/-+=<>?:"{}|,./;'//[/]?~!@#¥%……&*()――/-+={}|《》?:“”【】、;‘',。、]/g, '').replace(//s/g, "");if (value.length >= number) {this.$message({type: "warning",message: `輸入內容不能超過${number}個字符`});}return value;};

HTML部分

<el-input maxlength='15' :value="searchForm.logId" @input='e => searchForm.logId = validSe (e,15)' placeholder="請輸入日志ID"></el-input>

需要將v-model拆分為:value和@input

通過以上方法又擴展出以下方法

//只能輸漢字Vue.prototype.chineseOnly = function (value) {value = value.replace(/[^/u4E00-/u9FA5]/g, '');return value};//只能輸正整數Vue.prototype.idOnly = function (value) {value = value.replace(/[^0-9]/g, '');return value};//不允許輸漢字Vue.prototype.noChineseOnly = function (value) {value = value.replace(/[/u4E00-/u9FA5]/g, '');return value}; //逗號和數字Vue.prototype.programIdOnly = function (value) {value = value.replace(/[^0-9,]/g, '');return value};//數字和回車Vue.prototype.idsOnly = function (value) {value = value.replace(/[^/r/n0-9]/g, '');return value};//數值大小限定Vue.prototype.numberLimit = function (value) {value = value.replace(/[^0-9]/g, '');if (value >= 2147483647) {this.$message({type: "warning",message: `最大可輸入值為2147483647`});}return value};// 正整數Vue.prototype.onlyPositiveInteger = function (value) {value = String(value).match(/[1-9]/d*/g, "")return value === null ? '' : Number(value[0])};// 正整數(包含0)Vue.prototype.onlyPositiveInteger1 = function (value) {console.log(typeof (value));value = String(value).match(/[1-9]/d*|0/g, "")return value === null ? '' : Number(value[0])};// 負整數Vue.prototype.onlyNegativeInteger = function (value) {value = String(value).match(/^-[1-9]*/d*/g, "")return value === null ? '' : value[0] === '-' ? '-' : value[0] === '-0' ? '' : Number(value[0])};// 負整數(包含0)Vue.prototype.onlyNegativeInteger1 = function (value) {value = String(value).match(/^-[1-9]*/d*|0/g, "")return value === null ? '' : value[0] === '-' ? '-' : Number(value[0])};// 整數Vue.prototype.onlyInteger = function (value) {value = String(value).match(/^-?[1-9]*/d*|0/g, '')return value === null ? '' : value[0] === '-' ? '-' : value[0] === '' ? '' : Number(value[0])};// 整數區間Vue.prototype.onlySection = function (value, min, max) {if (min < 0) {value = String(value).match(/-?[1-9]*/d*/g, "")} else {value = String(value).match(/[1-9]*/d*/g, "")}// value = String(value).match(/-?[1-9]*/d*/g, "")value = value === null ? '' : value[0] === '-' ? '-' : value[0] === '' ? '' : Number(value[0])if (value < min) {return min} else if (value > max) {return max} else {return value}};

總結

以上所述是小編給大家介紹的vue+element項目中過濾輸入框特殊字符小結,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 布尔津县| 班戈县| 科技| 株洲县| 云安县| 庄浪县| 丹凤县| 应城市| 平远县| 固始县| 邵阳市| 横峰县| 驻马店市| 孟州市| 顺义区| 皮山县| SHOW| 富宁县| 定边县| 河南省| 凌海市| 什邡市| 乌拉特中旗| 陵水| 光山县| 镇雄县| 桐柏县| 沁水县| 左贡县| 镇原县| 西宁市| 洞口县| 新昌县| 印江| 长泰县| 原阳县| 麻城市| 河源市| 东兰县| 亚东县| 赞皇县|