-2

Hi i have a question about validate My country Identity Number (Malaysia)(12digit). My country first 6 digit number represent as date of birth, for example 880115 (YYMMDD) 1988-01-15 In angular, i need some advice for how to i catch first 6digit of ID then validate as date and if Under 19years old Will Cancel the registration.

"Here is my official requirement, Validate with first 6 digit of IC. If Age below 19, prompt message and reject the registration."

<label>Identity No: </label>
<input type = "text" name="Identity_No" id="Identity_No" ngModel #IdentityNo="ngModel" maxlength="12" minlength="12" required >
<div *ngIf="IdentityNo.touched" class="alert alert-danger">
 <div *ngIf="IdentityNo.errors?.required">
   Identity No is required
</div> 
   <div *ngIf="IdentityNo.errors?.minlength">
       must be 12 valid characters long.
   </div> 
</div>
                
Calvin Tkh
  • 51
  • 1
  • 6
  • 1
    Your question is overly broad. What are you not able to do? Get the first six characters of a string? Validate a date? Compare a date to the current date to calculate the age? Check whether the age is over 19? Show an error message? Or, are you just looking for someone to do your job for you? – Robby Cornelissen Jun 12 '18 at 03:52
  • @RobbyCornelissen i not looking for someone to do my job, i because i stucked this part few days, just looking for some suggestion about to get first 6 characters as string and generate as a date. maybe my question is abit confused you. – Calvin Tkh Jun 12 '18 at 05:35
  • [How to get the first characters from a string](https://stackoverflow.com/questions/39886730/javascript-how-to-get-first-three-characters-of-a-string) and [Converting a string to a date](https://stackoverflow.com/questions/7151543/convert-dd-mm-yyyy-string-to-date) – Robby Cornelissen Jun 12 '18 at 05:41

2 Answers2

1

on submit or on change get the string, i mean input value, then get first 6 char from string using

str.substring(0,6)

After that covert date into timestamp and compare with current timestamp if difference is more then 19 years it is ok. Otherwise it's invalid.

Robin gupta
  • 176
  • 2
  • 11
0

Use ngChange = checkUserAge() to detect user input, then you can cancel the registration by checking the user input.

tung yu
  • 94
  • 4