Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manipulate firstname and lastname entry

Status
Not open for further replies.

cleanair4me46

Technical User
Feb 3, 2009
41
US
I have a form with firstname in one field and lastname is another field.

I need to manipulate the entry so if someone enters Joe for the firstname and Smith for the second name it will be changed to Smith,Joe.

Here is my attempt but it just switched the fields and didnt manipulate how I wanted it:
Code:
var name = "Joe Smith"
var pattern = /^([a-z-]+)\s+([a-z-']+)$/gi;
name = name.replace(pattern, "$2,$1");
name = name.replace(/,/, " ");
 
Hi

And what if the visitor's name is 'Joe Adam Smith', without dash ( - ) ?

Anyway, I not understand what you want. You mentioned two [tt]input[/tt] field, but your example manipulates a single string.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top