在使用動態(tài)表單時對表單項進(jìn)行非空校驗(yàn)及正則校驗(yàn)。
使用手機(jī)號進(jìn)行校驗(yàn),示例如下:
動態(tài)表單的基本使用:https://ng-alain.com/form/getting-started/zh
基于基本示例,增加手機(jī)號必填與正則校驗(yàn)的例子:
@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: '手機(jī)號', pattern: '^1[0-9]{10}$' }, }, }; ui: SFUISchema = { '*': { spanLabelFixed: 100, grid: { span: 24 }, }, $mobileNumber: { widget: 'string', errors: { 'pattern': '請輸入11位手機(jī)號碼' } } }; submit(value: any) { }}
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持武林網(wǎng)。
新聞熱點(diǎn)
疑難解答