Solved

splitting variable before any special character

Posted on 2013-05-14
1
268 Views
Last Modified: 2013-05-14
Hi,

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?

Thanks
0
Comment
Question by:Al4ddin2
1 Comment
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39164843
var str = 'Harry & Sally';
var harry = str.split(/[^a-z0-9\s]/i)[0];
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
How to build a simple, quick and effective accordion menu using just 15 lines of jQuery and 2 css classes
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question