RE: [PHP] VB-->PHP

From: Date: Thu, 29 Jul 2004 09:59:00 +0000
Subject: RE: [PHP] VB-->PHP
Groups: php.general 
Request: Send a blank email to php-general+get-192166@lists.php.net to get a copy of this message
On 29 July 2004 10:00, Jay wrote: > Hi! > > Can someone pelase help me to convert the following Vbscript code to > PHP, i am really sucky at Regular Expression: > ---------CODE VBSCRIPT--------------------- > Function IsValid(strData,blIncludeAlpha,blIncludeNumeric) > Dim regEx, retVal,strPtrn > Set regEx = New RegExp > If blIncludeAlpha Then > strPtrn="a-zA-Z" > End If > If blIncludeNumeric Then > strPtrn="0-9" > End If > if blIncludeAlpha and blIncludeNumeric Then > strPtrn="a-zA-Z0-9" > End if > regEx.Pattern = "^[" & strPtrn & "]+$" > IsValid= regEx.Test(strData) > End Function Something like: function isValid($strData, $blIncludeAlpha, $blIncludeNumeric) { $strPattern = "/^[; if ($blIncludeAlpha): $strPattern .= "a-zA-Z"; endif; if ($blIncludeNumeric): $strPattern .= "0-9"; endif; $strPattern .= "]$/"; return preg_match($strPattern, $strData); } Cheers! Mike --------------------------------------------------------------------- Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: m.ford@leedsmet.ac.uk Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211

« previous php.general (#192166) next »