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
279 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 82

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 82

Expert Comment

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

Accepted Solution

by:
soupBoy earned 500 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now