splitting variable before any special character


I am reading in some data-params into a form and there is one hidden field that I need to populate that requires the data-param value to be stripped before any special characters.
So if the data-param value = 'Harry & Sally' then I would need to populate the hidden field with 'Harry '

Is there a way to split the value before any special character other than spaces?

Who is Participating?
leakim971Connect With a Mentor PluritechnicianCommented:
var str = 'Harry & Sally';
var harry = str.split(/[^a-z0-9\s]/i)[0];
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.