Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

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
?
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

The most up-to-date version of this article is on my Blog https://iconoun.com/blog/
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 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…
Suggested Courses

704 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