Link to home
Start Free TrialLog in
Avatar of Panos
PanosFlag for Germany

asked on

uppercase-lowercase in coldfusion

Hello experts.
How can i store in my database a string with the first letter-uppercase and the rest lowercase,whatever a client is writing in my form.firstname field.
The one i have is changing everything to lowercase like:
<cfset FirstName = rereplace(lcase(form.Firstname), "((^| )[a-z]{1})", "\U\1", 'all' )>

Any help?(please a none javascript solution)
ASKER CERTIFIED SOLUTION
Avatar of Coast Line
Coast Line
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Panos

ASKER

Hi
How can i use this out of a cffunction
I have an insert querylike
INSERT INTO.......
Values
 (<cfif  Form.Firstname NEQ "">
<cfset FirstName = rereplace(lcase(form.Firstname), "((^| )[a-z]{1})", "\U\1", 'all' )>
   <cfqueryparam cfsqltype="cf_sql_varchar" value="#Firstname#">,<cfelse>NULL,</cfif> .......
u can use them inside the insert query like:

you should call this template as an include file like:

<cfinclude template="upperFirst.cfm">

then

INSERT INTO.......
Values
 (<cfif  Form.Firstname NEQ "">
   <cfqueryparam cfsqltype="cf_sql_varchar" value="#upperFirst (Firstname)#">,<cfelse>NULL,</cfif> .......

That's ALL you have to do
this should <cfqueryparam cfsqltype="cf_sql_varchar" value="#upperFirst (Firstname)#">,<cfelse>NULL,</cfif> .......
be as
<cfqueryparam cfsqltype="cf_sql_varchar" value="#upperFirst (form.Firstname)#">,<cfelse>NULL,</cfif> .......
Avatar of Panos

ASKER

Hi again.
You have answered my question.I have a little problem now because i'm not using the english language and characters but the greek one.
The function i need is the nameCase function but that is changing the last letter in my string.
I can't write it down because none english characters can not be displayed.Have you any idea to solve this?
well i do not know but i think if u website is in greek language, then u need the find the equivalent of

([[:upper:]])([[:upper:]]*)","\1\L\2\E"\

in greek language..

like u can use google:

([[: ¿¿¿ :]])([[: ¿¿¿ :]]*)"," \ 1 \ L \ 2 \ ¿ "

i am not sure but it may work!

here is the link that i tried

http://translate.google.co.in/translate_t?hl=&ie=UTF-8&text=([[:upper:]])([[:upper:]]*)%22,%22\1\L\2\E%22&sl=en&tl=el#
Avatar of Panos

ASKER

No this is not solving the problem.Using the new code i get all uppercase.
This is the case where one problem is solved and the next one comes and again i stuck.
I will accept the first answer and make a new question for the new peoblem.
Thank you
Avatar of Panos

ASKER

Thak you.
regards
panos
Avatar of Panos

ASKER

Finally i found a solution without problems here:
http://www.wecodethings.com/lore/idx.php/0/032/article/ColdFusion-Initcap-Capitalize-the-first-letter-of-each-word.html.
      <cffunction name="initCap" access="public" output="false" returntype="String" hint="I capitalize the first letter of every word group">
              <cfargument name="inputString" required="false" type="String" default="" />
              <cfreturn rereplace(lcase(arguments.inputString), "(\b\w)", "\u\1", "all") />
      </cffunction>