[英]How to check format of a string in javascript
我對javascript還是很陌生,我找不到一個單一的指南來檢查字符串格式(除了整個代碼如何檢查電子郵件等)。
因此,我需要檢查我的變量是否采用這種格式-applicationcode0001。 文本將不會更改-像這樣的東西variable=="applicationcode"+[number]+[number]+[number]+[number]
如果您可以提供一些鏈接來檢查像這樣的字符串變量,我將非常高興。
謝謝,MJ
var myRe = /^applicationcode\\d{4}$/; console.log(myRe.test('applicationcode0001'));
var regex = RegExp('applicationcode[0-9]{4}','g'); var str1 = 'applicationcode1234'; console.log(regex.test(str1)); // expected output: true //
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.