p4.component.ts 1.24 KB
Newer Older
李彥志's avatar
李彥志 committed
1 2 3 4 5 6 7 8 9 10 11
import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-p4',
  templateUrl: './p4.component.html',
  styleUrls: ['./p4.component.css']
})
export class P4Component implements OnInit {

  number = '';
  value2: any;
12 13 14
  test: number;
  test2: number;
  test3 = '';
李彥志's avatar
李彥志 committed
15

16 17
  checkNumber(test): void {
    console.log(test);
李彥志's avatar
李彥志 committed
18

19 20
    if (test <= 0 || test === undefined) {
      alert('必須輸入大於0的數字');
李彥志's avatar
李彥志 committed
21
    } else {
22
      alert('輸入正確');
李彥志's avatar
李彥志 committed
23 24 25
    }
  }

26 27
  checkNumber2(test2): void {
    console.log(test2);
李彥志's avatar
李彥志 committed
28

29
    if (test2 === undefined || test2 === null) {
李彥志's avatar
李彥志 committed
30
      alert('只能輸入數字');
李彥志's avatar
李彥志 committed
31
    } else {
32
      alert('輸入正確');
李彥志's avatar
李彥志 committed
33 34 35
    }
  }

36 37
  checkNumber3(test3): void {
    console.log(test3);
李彥志's avatar
李彥志 committed
38

39 40
    if (test3.match(/([A-z])/g).length === 2 && (test3.match(/([0-9])/g).length === 3)) {
      alert('輸入正確');
李彥志's avatar
李彥志 committed
41
    } else {
42
      alert('只能輸入英文兩碼 + 數字三碼');
李彥志's avatar
李彥志 committed
43 44
    }
  }
李彥志's avatar
李彥志 committed
45

46 47 48 49 50 51 52 53 54 55 56 57 58
  // addNumber(inputRef: HTMLInputElement): void {
  //   console.log(inputRef.value);
  //   inputRef.value = '';

  //   this.value2 = +inputRef.value;

  //   if (this.value2 <= 0) {
  //     alert('請輸入大於0的數字');
  //   } else {
  //   alert('輸入正確');
  //   }
  // }

李彥志's avatar
李彥志 committed
59 60 61 62 63 64 65

  constructor() { }

  ngOnInit() {
  }

}