Re: [PHP-DB] [Regular expression] Format string to DD/MM/YYYY hh:mm
Balazs Hegedus ha scritto: ?php $date = '30/03/2983 12:00'; $pattern = '[0-3][0-9]/[0|1][0-9]/[1|2][0-9]{3,3}\s[0-2][0-9]:[0-5][0-9]'; I found this: ^([0-1]?\d)|(2[0-8]))\/((0?\d)|(1[0-2])))|(29\/((0?[1,3-9])|(1[0-2])))|(30\/((0?[1,3-9])|(1[0-2])))|(31\/((0?[13578])|(1[0-2]\/((19\d{2})|([2-9]\d{3}))|(29\/0?2\/[2468][048])|([3579][26]))00)|(((19)|([2-9]\d))(([2468]0)|([02468][48])|([13579][26]))\s(([01]?\d)|(2[0-3]))(:[0-5]?\d){2}$ But it accepts second too...can you help me to modify it? bye and thanks anyway, -- Giacomo -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] [Regular expression] Format string to DD/MM/YYYY hh:mm
Balazs Hegedus ha scritto: ?php $date = '30/03/2983 12:00'; $pattern = '[0-3][0-9]/[0|1][0-9]/[1|2][0-9]{3,3}\s[0-2][0-9]:[0-5][0-9]'; I found this: ^([0-1]?\d)|(2[0-8]))\/((0?\d)|(1[0-2])))|(29\/((0?[1,3-9])|(1[0-2])))|(30\/((0?[1,3-9])|(1[0-2])))|(31\/((0?[13578])|(1[0-2]\/((19\d{2})|([2-9]\d{3}))|(29\/0?2\/[2468][048])|([3579][26]))00)|(((19)|([2-9]\d))(([2468]0)|([02468][48])|([13579][26]))\s(([01]?\d)|(2[0-3]))(:[0-5]?\d){2}$ But it accepts second too...can you help me to modify it? bye and thanks anyway, damn thats ugly.. Personally I love regex, as some of you on this list may have found out the hard way.. But in a situation like this where I'd also want to verify the integers passed I'd simply use the regex to help me split the given datetime string into a 5/6 element array which I can then perform tests with Lets not forget: bool checkdate ( int month, int day, int year ) http://php.mirrors.ilisys.com.au/manual/en/function.checkdate.php Helps to ensure the date at least is a valid date and day for the given month.. Therefore I would do something like: $dtStr = preg_replace(/^(\d{2})\/(\d{2})\/(\d{2,4}) (\d{1,2}):(\d{2})$/, $1-$2-$3-$4-$5, $date); $dtArr = split(-,$dtStr); if(checkdate($dtArr[1], $dtArr[0], $dtArr[2]) AND $dtArr[3]=23 AND $dtArr[3]=0 AND $dtArr[4]=59 AND $dtArr[4]=0) { //date and time are valid. continue processing.. } its fairly short, has room to grow [ie changing format acceptance in regex] to allow for different seperators or even addition of seconds later down the track easily without having to dive into a untidy regex pattern. Let me know how you go... Best of luck! ---oOo--- Allowing users to execute CGI scripts in any directory should only be considered if: ... a.. You have no users, and nobody ever visits your server. ... Extracted Quote: Security Tips - Apache HTTP Server ---oOo--- --oOo---oOo-- Julien Bonastre [The_RadiX] The-Spectrum Network CEO ABN: 64 235 749 494 [EMAIL PROTECTED] www.the-spectrum.org --oOo---oOo-- -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.1.384 / Virus Database: 268.3.3/298 - Release Date: 30/03/2006 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] [Regular expression] Format string to DD/MM/YYYY hh:mm
try this : $date = 30/12/1982 15:30 if (preg_match(/\d{2}\/\d{2}\/\d{4}\s\d{2}:\d{2}/i,$date )) { echo Date is valid; } else { echo Date NOT valid; } hope it will help you -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] [Regular expression] Format string to DD/MM/YYYY hh:mm
On Thursday 30 March 2006 16:49, Arie Nugraha wrote: try this : $date = 30/12/1982 15:30 if (preg_match(/\d{2}\/\d{2}\/\d{4}\s\d{2}:\d{2}/i,$date )) { echo Date is valid; } else { echo Date NOT valid; } This is not correct since you don't check the ranges of the day digits, month digits, etc. The easiest way to check the string is to explode it by (space), then explode the first part by slash and the second by column, and at last check the ranges. A regular expression will be much more complex. hope it will help you -- Cyberly yours, Petar Nedyalkov Devoted Orbitel Fan :-) PGP ID: 7AE45436 PGP Public Key: http://bu.orbitel.bg/pgp/bu.asc PGP Fingerprint: 7923 8D52 B145 02E8 6F63 8BDA 2D3F 7C0B 7AE4 5436 pgp2hDxdXtsfb.pgp Description: PGP signature
Re: [PHP-DB] [Regular expression] Format string to DD/MM/YYYY hh:mm
Petar Nedyalkov ha scritto: This is not correct since you don't check the ranges of the day digits, month digits, etc. The easiest way to check the string is to explode it by (space), then explode the first part by slash and the second by column, and at last check the ranges. A regular expression will be much more complex. I know, but I would need of a regular expression...=( Giacomo -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] [Regular expression] Format string to DD/MM/YYYY hh:mm
Hi, this regex isn't perfect at all but might do the job. You should modify the pattern to match the year part against 2037 as a maximum and also don't forget to checkdate(). ?php $date = '30/03/2983 12:00'; $pattern = '[0-3][0-9]/[0|1][0-9]/[1|2][0-9]{3,3}\s[0-2][0-9]:[0-5][0-9]'; if (preg_match(!^$pattern$!, $date) === 1) { echo 'date is in valid form'; } else { echo 'date form is invalid'; } ? Hope it helps, Balazs -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] [Regular expression] Format string to DD/MM/YYYY hh:mm
Oops, \s matches any whitespace character, so if you need only space there you should change \s to space (this way it matches tab too). Balazs 2006/3/31, Balazs Hegedus [EMAIL PROTECTED]: Hi, this regex isn't perfect at all but might do the job. You should modify the pattern to match the year part against 2037 as a maximum and also don't forget to checkdate(). ?php $date = '30/03/2983 12:00'; $pattern = '[0-3][0-9]/[0|1][0-9]/[1|2][0-9]{3,3}\s[0-2][0-9]:[0-5][0-9]'; if (preg_match(!^$pattern$!, $date) === 1) { echo 'date is in valid form'; } else { echo 'date form is invalid'; } ? Hope it helps, Balazs -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Regular Expression
Ng Hwee Hwee wrote: Hi all, I somehow just couldn't get my regular expression syntax correct. Will you please help me? some examples of my valid string is: sinx0401-001-45 hkgx0403-020-12 jktx0402-000-01 bkkx0407-013-44 the definition is: 1st 4 characters - can only be sinx or hkgx or bkkx or jktx next 4 characters - numbers 0 to 9 next 1 character - a dash - next 3 characters - numbers 0 to 9 next 1 character - a dash - last 2 characters - numbers 0 to 9 (sin|hkg|bkk|jkt)x[0-9]{4}-[0-9]{3}-[0-9]{2} -- John Holmes php|architect - The magazine for PHP professionals - http://www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Regular Expression
thanx!!! it worked like a charm! =) just a question, i've tried adding a ^ to the front of your expressions and a $ to the end of your expression and it still worked.. but is it recommended? why didn't you use them? ^(sin|hkg|bkk|jkt)x[0-9]{4}-[0-9]{3}-[0-9]{2}$ hwee - Original Message - From: John Holmes [EMAIL PROTECTED] To: Ng Hwee Hwee [EMAIL PROTECTED] Cc: PHP DB List [EMAIL PROTECTED] Sent: Thursday, August 05, 2004 10:22 AM Subject: Re: [PHP-DB] Regular Expression Ng Hwee Hwee wrote: Hi all, I somehow just couldn't get my regular expression syntax correct. Will you please help me? some examples of my valid string is: sinx0401-001-45 hkgx0403-020-12 jktx0402-000-01 bkkx0407-013-44 the definition is: 1st 4 characters - can only be sinx or hkgx or bkkx or jktx next 4 characters - numbers 0 to 9 next 1 character - a dash - next 3 characters - numbers 0 to 9 next 1 character - a dash - last 2 characters - numbers 0 to 9 (sin|hkg|bkk|jkt)x[0-9]{4}-[0-9]{3}-[0-9]{2} -- John Holmes -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Regular Expression
Ng Hwee Hwee wrote: (sin|hkg|bkk|jkt)x[0-9]{4}-[0-9]{3}-[0-9]{2} thanx!!! it worked like a charm! =) just a question, i've tried adding a ^ to the front of your expressions and a $ to the end of your expression and it still worked.. but is it recommended? why didn't you use them? ^(sin|hkg|bkk|jkt)x[0-9]{4}-[0-9]{3}-[0-9]{2}$ Yeah, you should use them to ensure that the text is _only_ that code and not just contains it. Otherwise asdf sinx1234-123-12 asdf will pass. I just forgot. :) -- John Holmes php|architect - The magazine for PHP professionals - http://www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Regular Expression
thanx a million!! you really saved my day!! :o) hwee - Original Message - From: John Holmes [EMAIL PROTECTED] To: Ng Hwee Hwee [EMAIL PROTECTED] Cc: PHP DB List [EMAIL PROTECTED] Sent: Thursday, August 05, 2004 11:05 AM Subject: Re: [PHP-DB] Regular Expression Ng Hwee Hwee wrote: (sin|hkg|bkk|jkt)x[0-9]{4}-[0-9]{3}-[0-9]{2} thanx!!! it worked like a charm! =) just a question, i've tried adding a ^ to the front of your expressions and a $ to the end of your expression and it still worked.. but is it recommended? why didn't you use them? ^(sin|hkg|bkk|jkt)x[0-9]{4}-[0-9]{3}-[0-9]{2}$ Yeah, you should use them to ensure that the text is _only_ that code and not just contains it. Otherwise asdf sinx1234-123-12 asdf will pass. I just forgot. :) -- John Holmes php|architect - The magazine for PHP professionals - http://www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] regular expression help
try this $password = 'abcdef'; if (preg_match ('/\w\d\w/', $password)) { die (You must have a number between 2 letters in your password ... 0-9); } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] regular expression help
That does not work either... I can not make the statement fail!!! I have tried $password = 123456; and $password = abcdef; I have change the if statement to what is below and past in all letters and it still works? if (preg_match ('/\d/', $password)) { die (You must have a number between 2 letters in your password ... 0-9); // Larry -Original Message- From: Matt Matijevich [mailto:[EMAIL PROTECTED] Sent: Thursday, June 24, 2004 12:11 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: [PHP-DB] regular expression help try this $password = 'abcdef'; if (preg_match ('/\w\d\w/', $password)) { die (You must have a number between 2 letters in your password ... 0-9); } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php My Inbox is protected by SPAMfighter 2228 spam mails have been blocked so far. Download free www.spamfighter.com today! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] regular expression help
hi! is this correct: you want to check if there are two letters in the password wich do not surround a digit? if so this is what you need: ?php // dies $password = 'alfgoesswimming'; // dies too $password = 'a2lf4g2o4e7s9s3w9i0m5m7i0n3g'; // survives $password = 'a2l5f4g2o4e7s9s3w9i0m5m7i0n3g'; $found = array(); $pattern = '#[a-z_]{2}#i'; if(preg_match_all($pattern, $password, $found)0) { die('You must have a number between 2 letters in your password ... 0-9'); } else { die('password accepted'); } ? greez ma -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] regular expression help
ok... this still does not do what you want, because it does not consider that only digits should be between the letters... here is the correct solution: ?php // dies $password = 'alfgoesswimming'; // dies too $password = 'a2lf4g2o4e7s9s3w9i0m5m7i0n3g'; // survives $password = 'a2$5l5f4g2o4e7s9s3w9i0m5m7i0n3g'; $found = array(); $pattern = '#[^0-9]{2}#i'; if(preg_match_all($pattern, $password, $found)0) { die('You must have a number between 2 letters in your password ... 0-9'); } else { die('password accepted'); } ? hth greez ma Matthias Steinböck wrote: hi! is this correct: you want to check if there are two letters in the password wich do not surround a digit? if so this is what you need: ?php // dies $password = 'alfgoesswimming'; // dies too $password = 'a2lf4g2o4e7s9s3w9i0m5m7i0n3g'; // survives $password = 'a2l5f4g2o4e7s9s3w9i0m5m7i0n3g'; $found = array(); $pattern = '#[a-z_]{2}#i'; if(preg_match_all($pattern, $password, $found)0) { die('You must have a number between 2 letters in your password ... 0-9'); } else { die('password accepted'); } ? greez ma -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] regular expression help
i see... so the pattern you need is ?php $atLeast = 2; $pattern = '#\d{1}#'; if(preg_match_all($pattern, $password, $a) $atLeast) { echo 'password ok; contains at least '.$atLeast.' digits.'; } hth greez ma Larry Sandwick wrote: I would like to make sure that there is at least 1 number in the password ? // Larry -Original Message- From: Matthias Steinböck [mailto:[EMAIL PROTECTED] Sent: Thursday, June 24, 2004 1:41 PM To: [EMAIL PROTECTED] Subject: RE: [PHP-DB] regular expression help hi! is this correct: you want to check if there are two letters in the password wich do not surround a digit? if so this is what you need: ?php // dies $password = 'alfgoesswimming'; // dies too $password = 'a2lf4g2o4e7s9s3w9i0m5m7i0n3g'; // survives $password = 'a2l5f4g2o4e7s9s3w9i0m5m7i0n3g'; $found = array(); $pattern = '#[a-z_]{2}#i'; if(preg_match_all($pattern, $password, $found)0) { die('You must have a number between 2 letters in your password ... 0-9'); } else { die('password accepted'); } ? greez ma -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] regular expression help
you only want to check to see if there is at least one digit? If that is true, this should work: if(preg_match('/\d/',$password)) { echo 'password ok'; } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] regular expression help
[snip] That does not work either... I can not make the statement fail!!! I have tried $password = 123456; and $password = abcdef; I have change the if statement to what is below and past in all letters and it still works? if (preg_match ('/\d/', $password)) { die (You must have a number between 2 letters in your password ... 0-9); // Larry [/snip] sorry, this should be: if (!preg_match ('/\d/', $password)) { die (You must have a number between 2 letters in your password ... 0-9); } -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php