la***********@zipmail.com said the following on 5/23/2007 5:03 PM:
Hi,
I want to create a regular expression that will take a single input
name field and save the first and last names to two separate js vars.
The criteria for determining what is the separation would be the first
occurrence of a space (ascii code = 32). However, note that a user
may only enter one word or nothing at all. If the DOM id for the
field I want to parse is "nameField", how would I do this?
Why are you making it harder than it has to be?
var theNames = refToFormElement.split(' ');
If theNames has a length of 1, then there was no space.
If theNames has a length of 2, then there was a space.
If theNames has a length 2, then there was more than one space.
--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ -
http://jibbering.com/faq/index.html
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/