473,224 Members | 1,687 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,224 software developers and data experts.

blank space validation

pradeepjain
563 512MB
Hii guys,
I am using javascript validation..i am able to validate blank fields but if he enters a space in that field its not getting validated ..how to do it

if(document.form1.name.value ==""){
var name=document.form1.name
name.value="";
alert("Please Enter your Name");
name.focus();
return false;
}
Sep 12 '08 #1
6 23058
Nepomuk
3,112 Expert 2GB
As this is a JavaScript question and not a Java issue, I'm moving it to the JavaScript Forum. Please have a look at those two links to wikipedia, if you're unsure about the difference. They are two completely different languages.

Greetings,
Nepomuk (Moderator)
Sep 12 '08 #2
pradeepjain
563 512MB
ok sorry for that.


i found this solution..it works fine
Expand|Select|Wrap|Line Numbers
  1. function isEmpty( str){
  2.     strRE = new RegExp( );
  3.     strRE.compile( '^[\s ]*$', 'gi' );
  4.     return strRE.test( str.value );
  5. }
  6.  
but i wanted to know what exactly he is doing ..can any one explain me....


Thanks,
Pradeep
Sep 12 '08 #3
Ferris
101 100+
ok sorry for that.


i found this solution..it works fine
function isEmpty( str){
strRE = new RegExp( );
strRE.compile( '^[\s ]*$', 'gi' );
return strRE.test( str.value );
}

but i wanted to know what exactly he is doing ..can any one explain me....


Thanks,
Pradeep

Hi
the string '^[\s ]*$' is a regular expression.
[\s] matches the blank character.
[\s]* matches many blank characters.
^[\s]* matches at the start of the blank string,
[\s]*$ matches at the end of the blank string.
So , ^[\s ]*$' matches at the start of the blank string till the end of the blank string. It matches the blank string.

if "str.value" is a blank string , it will match the regular pattern '^[\s ]*$' . Then "strRE.test( str.value )" will be true.

You can have a look at Regular Expression syntax reference.
http://www.regular-expressions.info/reference.html

hope it helps.
Sep 12 '08 #4
acoder
16,027 Expert Mod 8TB
pradeepjain, as a full member for a long time now, you should know that we expect your code to be posted in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use the tags in future.

Moderator.
Sep 12 '08 #5
pradeepjain
563 512MB
pradeepjain, as a full member for a long time now, you should know that we expect your code to be posted in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use the tags in future.

Moderator.

hey really sorry for that .I think by mistake i clicked on QUOTE tag instead of CODE tag..i will see to that it doesn't happen again


thanks,
Pradeep
Sep 12 '08 #6
gits
5,390 Expert Mod 4TB
hi ...

the shown code could (and probably should) be improved in the following manner:

Expand|Select|Wrap|Line Numbers
  1. function isEmpty( str ){
  2.     var strRE = /^[\s ]*$/gi;
  3.     return strRE.test( str );
  4. }
first we should always declare the variables in functions by using the var keyword ... otherwise we would create a global variable which could cause problems later on and we should just avoid this. next we don't need the constructor and a function call to create a regExp instance ... we just use the literals for better performance ...

kind regards

PS: adapt this dependent to what input will be passed to the function but it would be better to pass the value itself instead of a dom-node so that the function doesn't need to know what it should evaluate ... just for the case the function should be reused for other cases later on ...
Sep 16 '08 #7

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

Similar topics

7
by: JDS | last post by:
Hi, all. I'd like to do the following, preferably *without* resorting to JavaScript: I have a long, dynamically-generated form questionnaire. Not all of the form fields are dynamically...
8
by: dmcconkey | last post by:
Hi folks, I have a client with four websites. Each site has a contact form that is identical. They all have "required" fields validated through a JavaScript onSubmit() function. Upon validation,...
0
by: Penguin | last post by:
Using Access 97, I've created a grading sheet. To save space, the subjects are in vertical columns on a sub-report, like so: Math Spelling Reading N C T A A E U A I ...
2
by: Ken Loomis | last post by:
Hello: I'm using the validating event on a text boxes to test for valid dates, doubles, etc. The problem is that if the field is not required and a blank value is OK and the user deletes a...
9
by: Alex Shirley | last post by:
Hi there Im simply trying to check for a blank or empty value in a textbox on my webform. In this instance I do not want to use a requiredfieldvalidator, I want to use a customvalidator (as I...
2
by: Amir | last post by:
I really hope someone can explain this behavior. I have spend quite a bit of time and tried a bunch of things, so far nothing has worked. I have a page on which I have a datagrid with template...
13
by: kurtj | last post by:
Hello Gurus: I have a validation script (below) that is somehow messed up. If the Name field is blank, I get the alert message, then the browser window goes to a blank document with the word...
4
by: BibhuAshish | last post by:
Hi, I wanted to delete a line from xml file which i did it. But after deletion of that line there is a blank space. Again if i am adding another line by using java that blank line remains as...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.