what is the reg exp to do this?

L

laredotornado

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?

Thanks, - Dave
 
S

scripts.contact

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?

Thanks, - Dave

var fullname=document.getElementById("nameField");
var firstSpace=fullname.indexOf(' ');
WScript.Echo(
"First Name:"+fullname.substr(0,firstSpace)
+"\nLast Name:"+fullname.substr(firstSpace+1)
)
 
S

scripts.contact

var fullname=document.getElementById("nameField");
var firstSpace=fullname.indexOf(' ');

WScript.Echo(
"First Name:"+fullname.substr(0,firstSpace)
+"\nLast Name:"+fullname.substr(firstSpace+1)
)

alert(
"First Name:"+fullname.substr(0,firstSpace)
+"\nLast Name:"+fullname.substr(firstSpace+1)
)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,426
Latest member
MrMet

Latest Threads

Top