在使用動態表單時對表單項進行非空校驗及正則校驗。
使用手機號進行校驗,示例如下:
動態表單的基本使用:https://ng-alain.com/form/getting-started/zh
基于基本示例,增加手機號必填與正則校驗的例子:
@Component({ selector: 'app-home', template: ` <sf [schema]="schema" [ui]="ui" (formSubmit)="submit($event)"></sf> `})export class HomeComponent { schema: SFSchema = { properties: { email: { type: 'string', title: '郵箱', format: 'email', maxLength: 20 }, name: { type: 'string', title: '姓名', minLength: 3 }, mobileNumber: { type: 'string', title: '手機號', pattern: '^1[0-9]{10}$' }, }, }; ui: SFUISchema = { '*': { spanLabelFixed: 100, grid: { span: 24 }, }, $mobileNumber: { widget: 'string', errors: { 'pattern': '請輸入11位手機號碼' } } }; submit(value: any) { }}以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持錯新站長站。
新聞熱點
疑難解答
圖片精選