-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>
                

3
  • 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? Commented Jun 12, 2018 at 3: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. Commented Jun 12, 2018 at 5:35
  • How to get the first characters from a string and Converting a string to a date Commented Jun 12, 2018 at 5:41

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.