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

Are You Using the Best Web Development Editor?

The worlds of web hosting and web development are constantly evolving. Every year we see design trends change, coding standards adapt and new frameworks/CMS created. With such a quick pace of change it’s easy to get lost trying to keep up.

See if your editor made the list.

Question has a verified solution.

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

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
Suggested Courses

628 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