From 5815d071850b36591fb9fab3c569a04bb9ef4d78 Mon Sep 17 00:00:00 2001 From: "YLHEALTH\\jackson.li" Date: Mon, 11 Feb 2019 16:03:31 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B0=A1=E6=98=93=E7=89=88=E9=A1=8C=E7=9B=AE(?= =?UTF-8?q?=E7=B7=B4=E7=BF=92=E4=B8=80=E4=BA=8C=E4=B8=89=E5=9B=9B)?= =?UTF-8?q?=E5=A4=A7=E8=87=B4=E5=AE=8C=E6=88=90=20=E5=8B=95=E5=B7=A5?= =?UTF-8?q?=E9=80=B2=E9=9A=8E=E7=89=88=E7=B7=B4=E7=BF=92=E4=BA=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/home/home.component.html | 2 -- src/app/p4/p4.component.html | 16 +++++++-- src/app/p4/p4.component.ts | 59 ++++++++++++++++---------------- src/app/p5/p5.component.html | 2 +- 4 files changed, 44 insertions(+), 35 deletions(-) diff --git a/src/app/home/home.component.html b/src/app/home/home.component.html index 8eb6bfd..35fb74e 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 c2bb696..26472b1 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 fb45881..085eb53 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 402bf81..fe4619e 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):
-- 2.26.2