Jump to content

Showing mele or female and brith date from entered personal id number


HaxorNab

Recommended Posts

Hi, I have a problem. I am doing one little job with php and html.
In html i have textbox in which person id must be entered (11 numbers) 
I need to do with php that when all 11 numbers are entered, date of birth and gender need to be shown,
For example:
if id is : 39310121111

first number stands for mele/female (if 3 mele if 4 female) all next numbers are date of birth 1993 10 12 (last 4 numbers doesnt have meaning)

Basicly question is. how to make syntax that entered id will be shown as gender and date of birth ? can't think of any ideas. new at php.

Edited by HaxorNab
Link to comment
Share on other sites

You should actually combine the data extraction with validation. Always expect to get wrong input.

 

Regular expressions can help you:

'/\\A(?<gender>3|4)(?<dob>\\d{6})\\d{4}\\z/'

Read: A 3 or 4 followed by 6 digits for the date of birth followed by another 4 digits.

 

You can then easily extract the ID parts:

<?php

const ID_PATTERN = '/\\A(?<gender>3|4)(?<dob>\\d{6})\\d{4}\\z/';



$input = '39310121111';

// validate the input and simultaneously extract the parts
$idParts = null;
if (!preg_match(ID_PATTERN, $input, $idParts))
{
    die('Invalid input. Please enter a valid 11-digit ID.');
}

// the individual parts
var_dump($idParts['gender'], $idParts['dob']);

Storing the year of birth as two digits isn't very smart, because now you need extra logic to distinguish between 19xx and 20xx. Let's not repeat the 2K problem.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.