473,395 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

To check whether user has entered has enter only blank spaces or some text.

Hi..
I need to find out whether user has entered only black spaces or some text which might have some spaces..
But i more interested to check for blanck spaces (by spacebar key).
how i will find out this. I used trim function, but it trims text also..i m using my own framework which i built for application.
Plz suggest me somthing..
following functions are not working.
element.length==0 and
element==null
Aug 24 '09 #1
5 4043
Dormilich
8,658 Expert Mod 8TB
@Sudhir123
then there’s something wrong with your trim function. you may work around it with String.replace().

note: Firefox 3.5 brings its own trim method.
Aug 24 '09 #2
gits
5,390 Expert Mod 4TB
show your trim function ... normally you trim the value and then check its length ... that is reliable ... but depends on a correct trim function. to check a value that is not empty but just contains whitespaces you could even use a regExp like this:

Expand|Select|Wrap|Line Numbers
  1. var s = '        ';
  2.  
  3. alert(/^[ ]+$/.test(s));
kind regards

PS: :) ahhh ... one minute late ... Dormilich's replace()-hint would work too when you want to work around your trim-function ...
Aug 24 '09 #3
Hi guys..
Thanks for ur replies...!! These r really worthful...!!
i found another solution...
I counted blank spaces and put validation for it.!!
Expand|Select|Wrap|Line Numbers
  1.                             var c=0;
  2.                 if (element) {
  3.                       for (var i=0; i<element.length; i++) {
  4.                             if (element.charAt(i) == " ") {
  5.                               c++
  6.                              }
  7.                              }
  8.                              } 
  9.     if(element.length==c)
  10.       return xyz. // according to ur need..!!
Aug 24 '09 #4
Dormilich
8,658 Expert Mod 8TB
@Sudhir123
IMHO a solid trim function is a better choice.

I thought of something like
Expand|Select|Wrap|Line Numbers
  1. if ("function" != typeof String.trim)
  2. {
  3.     String.prototype.trim = function()
  4.     {
  5.         return this.replace(/^\s*/, "").replace(/\s*$/, "");
  6.     }
  7. }
Expand|Select|Wrap|Line Numbers
  1. // use like
  2. var txt = input.value.trim();
Aug 24 '09 #5
gits
5,390 Expert Mod 4TB
@Dormilich
much better ... no question :) ... as a rule of thumb is that loops are to avoid wherever it is possible ...

kind regards
Aug 24 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Tee | last post by:
Hi, Is there any way to check whether user has changed the data in a DataGrid? Thanks, Tee
6
by: rpgfreak | last post by:
I have a textbox where u have to input an URL and when u press on a "GO" button, my browser window navigates to the URL, but if the textbox is in focus and I finish typing the URL, and then press...
0
by: tenko | last post by:
here's a question regarding changing units, say from g to kg without changing the entire codes.... my mathematical equation uses KG (kilograms), but the user can choose whether to enter values in...
3
kamill
by: kamill | last post by:
how can i remove blank spaces from text file......is there any function to remove a perticular chr from file...
3
by: ShaeMills via AccessMonster.com | last post by:
In my table I imported from .txt, one of my columns has blank spaces. The column is as follows, how do I eliminate the blank spaces in between the second and third, and fifth and sixth digits? ...
1
by: pmmwan | last post by:
i want to make deployment for window application using vs.net 2005. In deployment,I like to check whether user machine has .net framework. if not,i want to install.I think i have to use merge...
4
by: Thimali | last post by:
Hi all, I have a web page which is having a text box.I have already validated this using java script.Now i want to validate this same text box without prompting the error message.I need to change...
8
by: unkietee | last post by:
Hi Experts, my first post here! I hope you can help me. I have a basic form which I want the user to enter either a number (postcode/zipcode) or text (suburb). When they hit submit I want to...
1
by: ghjk | last post by:
I'm writing web application using jsp. I want to check user entered values is blank or not. This is my code and I got and error saying ".eqls on incompatibletypes()" . Anyone please help me.. if...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.