Page 1 of 1
coding dought in string
Posted: Sun Jun 21, 2009 4:00 am
by kuttus
hai hello i have a dought in string coding like example my string is"computer" where how can i separate each one and apply function for each one like validating each section as like below
c-->for c i need to give a specific range like it should present in between a-d
om-->here i need to apply the range for this two at time like taking in one group (om)
pu-here also so same as above
can u help me please.....
Re: coding dought in string
Posted: Sun Jun 21, 2009 4:43 am
by requinix
How about something more specific. Are you trying to validate the word? Are you splitting it into separate, special parts and then processing them?
A regular expression can do this, but unless you want to learn them yourself (it'll take lots of time) then you should explain what the exact validation criteria are.
Re: coding dought in string
Posted: Sun Jun 21, 2009 9:47 am
by kuttus
ok see i am developing a validation tag for the civil id of mine where what i need to do i will explain ok
the civil id is of containing 12 numbers
civilid number example :-285102101456
where the first num 2 will denote the century like if the date of birth year is 1986 then the 19 stands for 2 and if it is 18 the starting will be 1 and if it is 20 the starting will be 3 &and if any body will enter 4or more means it should show error.
where the next two number shows ie 85 the year which we born so for tht we can fix the range 00-99 but hw can we access the two string at strech and give the issue.
where the next two number 10 shows the month we have born so for tht we can fix the range 1-12 but hw can access the two string at astrech and give the issue.
where the next two number 21 shows the day we have born so for tht we can fix the range 1-31 but hw can access the two string at astrech and give the issue.
where the next five number is random number it can be any thing like in the range between 00000-99999 so hw can we apply this commands for each string which i have seperated above
like how we can take two string numbers at a time and apply the command i think u understand what i need
Re: coding dought in string
Posted: Sun Jun 21, 2009 4:41 pm
by requinix
So
- First digit is 1-3
- Second+third is 00-99
- Fourth+fifth is 01-12
- Sixth+seventh is 01-28/29/30/31
- Eighth and on is 00000-99999
Code: Select all
function validateID($number) {
// written out, could use substr() if you wanted
$century = $number[0];
$year = $number[1] . $number[2];
$month = $number[3] . $number[4];
$day = $number[5] . $number[6];
$sequence = $number[7] . $number[8] . $number[9] . $number[10] . $number[11];
if ($century == "1") $year += 1800;
else if ($century == "2") $year += 1900;
else if ($century == "3") $year += 2000;
else return false;
if (!checkdate($month, $day, $year)) return false;
if (strlen($sequence) != 5 || !ctype_digit($sequence)) return false;
return true;
}
validateID("285102101456");
Re: coding dought in string
Posted: Mon Jun 22, 2009 3:34 am
by kuttus
ok how u will compare it with the date like i am having one coloum for date and one coloum for civil id both should compare and give the validation according to the data entering in both. pls if u cn do it and give me ok