Archive for November, 2007

Trouble with PHP regular expression; REG_ERANGE error

November 29th, 2007

I had a situation where I needed to validate an email address that included an apostrophe. It is not widely known that the apostrophe (and a bunch of other symbols for that matter) are valid characters in the official RFC2822 specification for email address formats.

Anyway, I kept getting an error when I tried to add the apostrophe to my character classes in my regex. It gave me a strange error referencing REG_ERANGE. After some googling, I came across this blog post which led me to the answer. The problem is related to the placement of the dash (”-”) character in the regex.

Example 1:

if (ereg("[^a-zA-Z0-9_-.]", $userid)) {
    echo 'bad';
}
else {
    echo 'good';
}

The problem? The dash, or hyphen, being before the period. It thinks it’s a range, like you see in a-z. This may not be a bug, per se, but it’s certainly not smart enough for me.

The solution? Simply put the dash at the end of the regex.

Example 2:

if (ereg("[^a-zA-Z0-9_.-]", $userid)) {
    echo 'bad';
}
else {
    echo 'good';
}

No thanks, Chuck Norris… or Mike Huckabee

November 27th, 2007

I’m still making up my mind about the pantheon of Republican candidates for president. I was briefly excited about the candidacy of former Arkansas governor Mike Huckabee. Then I started doing some research…

Even though I might draw the ire of Chuck Norris (have you seen this commercial? hilarious!), I can NOT handle the following clip:

[youtube]http://www.youtube.com/watch?v=DaJW7nXw30A[/youtube]

From what I gather – there is broad consensus that the go-to option used to pay for government programs during Huckabee’s administration was to raise taxes.

NO THANKS!

Why I switched to a new IDE for PHP development

November 27th, 2007

I’ve been using Dreamweaver for about 10 years in some form or fashion. It actually started when I purchased Allaire HomeSite 3.0 in 1997. Macromedia purchased Allaire in 2001 and eventually merged HomeSite with their Dreamweaver product. Dreamweaver 8 is what I’ve been using for the past 2 years; that is, until I found PHP nirvana!

I have tried other IDE’s off and on for the past 5 years – trying to get more of a Visual Studio experience. I was really jealous of the code-completion and hinting features that were available in VS. Dreamweaver does ok at basic function hints for PHP, but nothing I found did a great job of combining all the site management features of Dreamweaver with the intelligent code parsing (ie. reading my classes and adding them to the code-completion hints). I’ve tried Eclipse with its PHP plug-in, UltraEdit, Zend Studio, phpDesigner and probably some others that I’m not listing.

PhpED Workspace

» Read more: Why I switched to a new IDE for PHP development

On-the-fly Form Validation with JavaScript Regular Expressions

November 19th, 2007

I needed to check a text input field on a form to allow only specific values as the user typed in the field. The regular expression only allows characters a-z, numbers 0-9, the “dash” symbol and the underscore. Not sure why, but I had to break out the check for a space into a second regex.

Here's the JavaScript function:
<script language="javascript" type="text/javascript">
function testField(oField) {

	var illegalChars = /[^a-zA-Z0-9_-]/;
	var spaceChars = /\s/;
		// allow only letters, numbers, dashes and underscores
	if (illegalChars.test(oPrefix.value) || spaceChars.test(oPrefix.value)) {
		alert("The prefix may only contain letters, numbers, dashes and underscores.");
		oPrefix.value = oPrefix.value.substring(0,oPrefix.value.length-1).toUpperCase();
	}
	else {
		oPrefix.value = oPrefix.value.toUpperCase();
	}

}
</script>

And here's the HTML form that calls the script through the "onKeyUp" action.

<form name='frmTest' method="POST" action="somepage.php">
Text: <input type='text' name='someFieldName' value='' maxlength="5" style="width:65px;"  onkeyup="testField(this)">
</form>

Incoming Deacs Looking for a National Championship

November 19th, 2007

I hope these guys are as good as we think they are. They certainly seem to be coming in with a bit of swagger about them.

Top class has fond memories of coach
This article is mostly about the 3 top recruits and their brief relationship with late head-coach Skip Prosser. But the last few paragraphs are exciting to think about…

Looking ahead

Talk to Aminu, Walker or Woods and they all have one goal in mind: a National Championship. Walker said he knew that the Deacons could be in that position as soon as he gave his nod to the program.

“As soon as I committed to Wake Forest, I started getting in contact with Tony Woods and he was telling me that he was going to choose between Florida and Wake Forest,” Walker said. “As soon as he said that, I knew that we were going to be something special. I was looking forward to that. Then when Al-Farouq came on with Tony, I was speechless.

“I know we are going to come in, work hard and do what we have to do to win a national championship.”

Aminu said he wants to play with a different mind-set this year, in honor of Prosser.

“I think there is a little more fire knowing that you were the last guy to commit to him. It kind of makes you want to dive onto the floor a little harder and a little more often. I think it’s motivating,” he said.

Walker shares the same sentiment.

“All Coach Prosser ever said to me was, ‘That I can’t wait to see you play. I know you’ll be a successful basketball player.’ I was looking forward to that so much.

“I was depressed for a few days. I could barely eat. When I dedicate these games, it is going to be real meaningful. I know Al-Farouq and Tony feel the same way.”

If You Could Only See

November 8th, 2007

This morning I had the “party shuffle” feature going on iTunes. I heard “If You Could Only See” from the band, Tonic, coming through the speakers and remembering that this was the first mp3 I had, the thought occurred to me that perhaps the file modified date would tell me the exact date & time of when that was!

Sure enough. Aug 30, 1997 at 8:10PM EST. I’d say I was pretty early in the movement don’t you think?

If You Could Only See