Form validation :: Capitalizing first letters

apps

#1

Hi

I am processing some php forms right now that automatically get generated into Goldmine. Everything works fine, but now I need to get some of the text fields to validate the case coversion of the first letter of each word to uppercase, and all other letters in the word are lowercase. Does anyone know how to do this, I am googling, but not finding a simple solution.

Barbara


#2

Barbara,

In my view, you don’t care that the user typed it right, but that it’s converted to Uppercase first letter, then lower case rest? So rather than tell the user he’s wrong, you can get there from here, right?

Assuming that’s OK, have a look at:
http://us2.php.net/manual/en/function.ucfirst.php
and/or
http://us2.php.net/manual/en/function.strtolower.php

By combining the two functions, as shown in the PHP docs, look at the final line below.

$bar = ‘HELLO WORLD!’;
$bar = ucfirst($bar); // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!

This is how I read your question. Other possibilities include using regular expressions, etc., but I feel these functions fit your need. If I misunderstood, give me another shot by explaining where this is off.

As an aside, by using the BINARY keyword in a MySQL query, you can make case matter (case sensitive) when executing a query. So, if you’d ever find yourself having to see if a user keyed a case-sensitive password into a form correctly, BINARY might help you out there.

Jim


#3

Jim, that is exactly what I am looking for…too much time at the pub tonight to put that into action tonight, but I will try tomorrow. thanks for the great response.

Barbara


#4

To add to the above, if your data is a name, ucwords() might be better:

$string = "hello world"; $string = ucwords($string); $string is now “Hello World”


#5

Thanks to both of you!

ucwords was exactly what I needed!

Works like a charm!!