Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
4
rated 0 times [  11] [ 7]  / answers: 1 / hits: 23853  / 12 Years ago, tue, november 13, 2012, 12:00:00

I know I can use the following to check if a string is empty in JavaScript:



 if(Message != '')


How would I check to see if a string 'Message' in this case - is empty and doesn't contain a number of spaces. eg:



 '    '


would I need to use regular expressions?


More From » jquery

 Answers
4

jQuery doesn't replace Javascript.
You can use:



if (Message.replace(/s/g, ).length > 0) {
// Your Code
}


Having said that, if you really want jQuery version, try this:



if ($.trim(Message).length > 0) {
// Your Code
}


Or, so long as you're only targeting IE9+ and modern browsers, you can use the built in trim function.



if (Message.trim().length > 0) {
// Your Code
}

[#82030] Sunday, November 11, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rickjordond

Total Points: 100
Total Questions: 105
Total Answers: 90

Location: Sweden
Member since Mon, May 8, 2023
1 Year ago
;