diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index 8eb6bfd74b9a68a4fd6bc495a29887843705a138..35fb74e3107708aa66540272c811f6686a82a0bb 100644 --- a/src/app/home/home.component.html +++ b/src/app/home/home.component.html @@ -53,8 +53,6 @@ cnt:
icon - - diff --git a/src/app/p4/p4.component.html b/src/app/p4/p4.component.html index c2bb69662c77406f37aa8fdb1cebebf9632192a9..26472b18ba72aca31be7f739de46ec6be2594b24 100644 --- a/src/app/p4/p4.component.html +++ b/src/app/p4/p4.component.html @@ -5,9 +5,9 @@ 一.必須輸入大於0,若輸入小於或等於0,則alert訊息
二.只能輸入數字,若輸入欄位不符,則alert訊息
三.只能輸入英文兩碼+數字三碼,若輸入欄位不符,則alert訊息 - +
- 欄位一 :

+ (keyup.enter)="addNumber3($event.target)">

--> + + 欄位一 : +
+ 欄位二 : +
+ + 欄位三 : +
+ diff --git a/src/app/p4/p4.component.ts b/src/app/p4/p4.component.ts index fb45881c817c7e364799994d28f7ed9dba12909a..085eb53303fd5d9464701358d045b7b96fa287f8 100644 --- a/src/app/p4/p4.component.ts +++ b/src/app/p4/p4.component.ts @@ -9,52 +9,53 @@ export class P4Component implements OnInit { number = ''; value2: any; + test: number; + test2: number; + test3 = ''; - addNumber(inputRef: HTMLInputElement): void { - console.log(inputRef.value); - inputRef.value = ''; + checkNumber(test): void { + console.log(test); - this.value2 = +inputRef.value; - - if ( - this.value2 > 0 - ) { - alert('輸入正確'); + if (test <= 0 || test === undefined) { + alert('必須輸入大於0的數字'); } else { - alert('請輸入大於0的數字'); + alert('輸入正確'); } } - addNumber2(inputRef: HTMLInputElement): void { - console.log(inputRef.value); - inputRef.value = ''; + checkNumber2(test2): void { + console.log(test2); - this.value2 = new Number(inputRef.value); - - if ( - this.value2 !== Number - ) { + if (test2 === undefined || test2 === null) { alert('只能輸入數字'); } else { - alert('輸入正確'); + alert('輸入正確'); } } - addNumber3(inputRef: HTMLInputElement): void { - console.log(inputRef.value); - inputRef.value = ''; + checkNumber3(test3): void { + console.log(test3); - this.value2 = new Number(inputRef.value); - - if ( - this.value2 !== Number - ) { - alert('欄位只能輸入英文兩碼 + 數字三碼'); + if (test3.match(/([A-z])/g).length === 2 && (test3.match(/([0-9])/g).length === 3)) { + alert('輸入正確'); } else { - alert('輸入正確'); + alert('只能輸入英文兩碼 + 數字三碼'); } } + // addNumber(inputRef: HTMLInputElement): void { + // console.log(inputRef.value); + // inputRef.value = ''; + + // this.value2 = +inputRef.value; + + // if (this.value2 <= 0) { + // alert('請輸入大於0的數字'); + // } else { + // alert('輸入正確'); + // } + // } + constructor() { } diff --git a/src/app/p5/p5.component.html b/src/app/p5/p5.component.html index 402bf810b5679683aff1f92833b98d04e8844739..fe4619e51008496755791a4a0813daec87c381b3 100644 --- a/src/app/p5/p5.component.html +++ b/src/app/p5/p5.component.html @@ -14,7 +14,7 @@ 姓名:
性別:
- 手機電話(4-3-3):
+ 手機電話(4碼-3碼-3碼):
生日(YYYY/MM/DD):
目前年收入(XXX,XXX):