python 如何區分return和yield
阿新 • • 發佈:2020-09-23
1、簡訊模板內容
驗證碼 ${username} 12345 驗證碼 ${username} 12345 驗證碼 ${username} 12345
從程式碼中提取 username,並判斷驗證碼 username中只存在英文字母
2、內容校驗,提取模板中${}的內容並且,內容只能使用英文
smsTemplateContentChange(value){ // 簡訊模板內容 校驗 const error = this.smsTemplateForm.get('templateContent').getError('pattern'); if (error){ return; }else{ this.smsTemplateForm.get('templateContent').setErrors(null); } const reg = /\$\{((?!\{).)*\}/g; const matchStr = value.match(reg); const resultList = new Set(); this.paramsList = new Set(); const pattern = '^[a-zA-Z]{1,}$'; const regex = new RegExp(pattern); let isError = false; if (matchStr){ matchStr.forEach((item: string) => { const result = item.replace('${','').replace('}',''); if (!result.match(regex)){ isError = true; } resultList.add(result); }); if (isError){ // 設定錯誤資訊 this.smsTemplateForm.get('templateContent').setErrors({errorParams: '引數只能使用英文'}); }else{ this.paramsList = resultList; } } // console.log(value.match(reg).replace('${','')); }
3、前端html
<se label="簡訊模板" [error]="{ required: '請輸入簡訊模板',pattern: '最大長度不超過200!',errorParams: '${}引數中只能使用英文'}"> <textarea formControlName="xxx" [(ngModel)]="smsTemplateVo.xxx" (ngModelChange)="smsTemplateContentChange(smsTemplateVo.xxx)" nz-input required></textarea> <div ><strong>提取可用引數:</strong><nz-tag *ngFor="let tag of paramsList" nzColor="default">{{tag}}</nz-tag></div> </se>
4、最終效果
到此這篇關於Angular簡訊模板校驗程式碼的文章就介紹到這了,更多相關Angular簡訊模板校驗內容請搜尋我們以前的文章或繼續瀏覽下面的相關文章希望大家以後多多支援我們!