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
283 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 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

Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Question has a verified solution.

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

Introduction HyperText Transfer Protocol (http://www.ietf.org/rfc/rfc2616.txt) or "HTTP" is the underpinning of internet communication.  As a teacher of web development I have heard many questions, mostly from my younger students who have come to t…
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.
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…

739 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