I have got a UITextfield with the following format . It is a Civil ID which we usually get to see in Gulf Countries. So I need to validate the same in my UITextfield in Swift.
Civil ID format - NYYMMDDNNNNN where N a digit, YY last two digits of birth year, MM birth month, DD birth date..
Please tell me how to do validation for this. I am currently validating the Date of Birth using the objective c code:
NSString *dateFromTextfield = @"07/24/2013";
// Convert string to date object
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"MM/dd/yyyy"];// here set format which you want...
NSDate *date = [dateFormat dateFromString:dateFromTextfield];
But how to do the same for my format requiring "NYYMMDDNNNNN" in swift.
First, allow your textfield input is digit only and give limit as well, in your case 12 character needed so give 12 characters limit - below is the code -
After that just validate whether user date of birth and entered date of birth is correct or not on submit button action like below -
Hope it will work for you.