Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Jquery how do i strip out all the characters except the number decimal value: ex Recommended Score [.453 - Low]

Posted on 2013-01-31
4
Medium Priority
?
291 Views
Last Modified: 2013-02-06
Jquery how do i strip out all the characters except the number decimal value: ex Recommended Score [.453 - Low]  I just want to get the .453.
0
Comment
Question by:cbrune
  • 2
4 Comments
 
LVL 83

Expert Comment

by:leakim971
ID: 38841036
check this page : http://jsfiddle.net/wjjk2/
score = s.match(/[(\.|\d]+/)[0];

Open in new window

0
 
LVL 11

Expert Comment

by:mcnute
ID: 38841085
You can do it with pure javascript which is considered to be faster because no transcripting from jquery to javascript happens in the background.

var str = 'ex Recommended Score [.453 - Low]';
var substr = str.split('[');
str = substr[1].substring(0,4);

Open in new window

0
 
LVL 83

Expert Comment

by:leakim971
ID: 38841132
better one :
score = s.match(/\d*\.\d*/);
0
 
LVL 8

Accepted Solution

by:
soupBoy earned 2000 total points
ID: 38841329
leakim971 beats my solution hard in the face....  but here is my two cents...looping

Check out the jsFiddle I created: http://jsfiddle.net/kEk8y/1/

Here was my code:
//This will only work if there is one number in the field...
//Fails hard with multiple number values in single field
var fields = $('.fieldsToSearch');
    
$.each(fields, function(index, elm){
   var text = $(elm).text(),
        arr = text.split(' ');
    
    for(var x=0; x < arr.length; x++){
        if(isNaN(arr[x])){
            arr.splice(x,1)
            x = x -1;
        }
    }
    
    //set the old value, just for safe keeping and update text
    $(elm).data('oldValue', text).text(arr[0]);
});

Open in new window


leakim971's solution is the best option....
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

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.
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn how to dynamically set the form action using jQuery.
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…

927 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