Log in

View Full Version : split a string



mhodgson
05-01-2007, 12:18 PM
I know I can split a string based on one delimiter
e.g.
var field=input.value.split("/")[0]
will split a field input string at every "/"
I would like to give a user the option of using "/ "or "-" or "." as a delimiter.

I can't seem to get this to work as easily as in php.

shachi
05-01-2007, 01:21 PM
try something like this:

somestring.split(userinput);

that's basically it.

jscheuer1
05-01-2007, 03:22 PM
var re=new RegExp('[/\.-]');
var field=input.value.split(re)[0]

Or:


var field=input.value.split(/[\/\.-]/)[0]

mhodgson
05-02-2007, 11:44 AM
Problem solved many thanks.