Thursday, April 25, 2024
 Popular · Latest · Hot · Upcoming
187
rated 0 times [  189] [ 2]  / answers: 1 / hits: 34711  / 10 Years ago, tue, may 6, 2014, 12:00:00
var $one = $('#oneClueShow');
var x = $(#clueOneInput).find('input[type=text]').val();
if(x == 'D R' || x == 'd r'|| x == 'D r'|| x == 'd R'|| x == 'd'|| x == 'r' || x == 'd R' || x == 'T A')


Above is a snippet of java/ I have. What it does is takes an input -- then checks for a match. The bug I'm looking to resolve is if there are spaces after or before it isn't recognized.



For example within the input someone can type 'D R' no problem. If a space is added like so 'D R ' then it no longer recognizes the input.



Is there something I can do to affect the input to ensure no space before/after prior to button click? I've been looking into replace, but can't seem to get it going.



A reference for what I've been looking at : http://www.w3schools.com/jsref/jsref_replace.asp


More From » jquery

 Answers
92

You can use $.trim



$.trim(yourstring)


which will allow for cross browser compatibility



In your case it would be



var x = $.trim($(#clueOneInput).find('input[type=text]').val());

[#71166] Sunday, May 4, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
noa

Total Points: 579
Total Questions: 83
Total Answers: 93

Location: Sweden
Member since Mon, Aug 10, 2020
4 Years ago
;