cleanair4me46
Technical User
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:
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(/,/, " ");