Copy link to clipboard
Copied
I'm new to Coldfusion and I've never really used regular expressions before. How would I write a ColdFusion function (or just a conditional statement) to check if a form variable is a match for an IP network (44.42.94.0/18)?
I'm just basically looking to see if the backslash "/" character is in the string.
Copy link to clipboard
Copied
newguy1300 wrote:
I'm just basically looking to see if the backslash "/" character is in the string.
The simplest method for this would be <cfif find(ipstring,"/") GT 0>
A regex expression that might do what you want, completely untested would be ([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}\[0-9]{1,???} I'm not sure how many digits you want to allow after the slash. Replace the question marks with that number.
Copy link to clipboard
Copied
The simplest method for this would be <cfif find(ipstring,"/") GT 0>
I think using find() is a better solution that trying to concoct a regex for this, but... you might want to check the order of parameters for find()...
http://livedocs.adobe.com/coldfusion/8/htmldocs/functions_e-g_21.html#5177400
--
Adam
Copy link to clipboard
Copied
It is always good to check the documentation.
But I do find it a bit annoying that the ColdFusion string functions seem to be some of the most inconsitant in what order the comon paramters come.
Copy link to clipboard
Copied
There are actually plenty of well-developed regular expression strings available on the Internet, which you can simply "copy and use." You don't have to spend too much time figuring-out the correct pattern of chicken scratches.
It's not quite as convenient as saying "use Regexp::Common::URL;" but one cannot have everything in "less-enlightened" languages like CF...
You do need to understand them, however. When you look at the string given in a previous reply, you do need to understand the meaning of all those symbols, and you need to practice the art of being able to cook them up extemporaneously.