473,397 Members | 2,033 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,397 software developers and data experts.

Javascript validation for spaces in text box

18
My Text box can accept all types of data like alphabets,numeric,special characters ... Should give an error message 'if space is not a valid value '
when i am clicking a button... in
asp.net with c# through javascript.(javascript validation after clicking a button).
Mar 24 '08 #1
21 16843
kenobewan
4,871 Expert 4TB
My Text box can accept all types of data like alphabets,numeric,special characters ... Should give an error message 'if space is not a valid value '
when i am clicking a button... in
asp.net with c# through javascript.(javascript validation after clicking a button).
This is still a JS problem. Suggest using click event and regular expressions. HTH.
Mar 24 '08 #2
kiran83
18
please send me javascript code for that(Space validation) it is very importent in my project...
Mar 24 '08 #3
kiran83
18
i was tryed the below code


function validate()
{
if (document.getElementById("<%=TextBox1.ClientID%>") .value=="")
{
alert("No Feild can not be blank");
document.getElementById("<%=TextBox1.ClientID%>"). focus();
return false;
}
}

this code only validate without blank but i want to without spaces validation

please help me...
Mar 25 '08 #4
kiran83
18
please reply me for the abobe question...
Mar 25 '08 #5
malav123
217 100+
please reply me for the abobe question...
Hi Kiran,

You can use Ascii value for validation... or you can use trim function to remove all spaces from your text boxes...
Mar 25 '08 #6
kiran83
18
how to use ascii value or trim for that text box
Mar 25 '08 #7
malav123
217 100+
how to use ascii value or trim for that text box
HI,
Fisrt of all tell me what you needs exactly ? do you want to put validation in which spaces not allows in textbox or you want to cheks only blank textbox validation ?? I think you don't want users to put spaces in text box.. right ? tell exact requirement than i will tell you how to use it because i have already used such validation in my project....
Mar 25 '08 #8
kiran83
18
validation in which spaces not allows in textbox
Mar 25 '08 #9
kiran83
18
please reply me for the above question...
Mar 25 '08 #10
gits
5,390 Expert Mod 4TB
have a look at the following example:

Expand|Select|Wrap|Line Numbers
  1. function validate() {
  2.     var field = document.getElementById("<%=TextBox1.ClientID%>");
  3.     var val   = field.value.replace(/^\s+|\s+$/, '');
  4.  
  5.     if (val.length == 0) {
  6.         alert('wrong value');
  7.     }
  8. }
  9.  
kind regards
Mar 25 '08 #11
kiran83
18
Thank you for sending the code.


kiran
Mar 25 '08 #12
gits
5,390 Expert Mod 4TB
no problem ... does it work for you?

kind regards
Mar 25 '08 #13
malav123
217 100+
If you want to validate the textboxes for space than you can use followin java script function,

function trimAll(sString)
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}
Mar 25 '08 #14
gits
5,390 Expert Mod 4TB
yes ... that is another way to trim a value that is done with the replace-method and a regex in the above code:

Expand|Select|Wrap|Line Numbers
  1. var val = field.value.replace(/^\s+|\s+$/, '');
  2.  
it could be just one line ;)

kind regards
Mar 25 '08 #15
malav123
217 100+
Ya it's true....
this will benificial for me also..
thanks....
Mar 25 '08 #16
gits
5,390 Expert Mod 4TB
Ya it's true....
this will benificial for me also..
thanks....
no problem :) ... glad when it helps you ... and a note: whenever string-operations have to be done in javascript we could try to use regex for that. the downside of it is just the 'readability' ... sometimes regex looks very 'cryptic' and hard to read ...

kind regards
Mar 25 '08 #17
malav123
217 100+
no problem :) ... glad when it helps you ... and a note: whenever string-operations have to be done in javascript we could try to use regex for that. the downside of it is just the 'readability' ... sometimes regex looks very 'cryptic' and hard to read ...

kind regards
Hi,
i am using one check box in my project and when i clicks on check box one pannel opens, i have write the code for this on server side but i want to write the code of same in javascript... i mean on client side, so please give me solution for my problem....
Mar 27 '08 #18
gits
5,390 Expert Mod 4TB
Hi,
i am using one check box in my project and when i clicks on check box one pannel opens, i have write the code for this on server side but i want to write the code of same in javascript... i mean on client side, so please give me solution for my problem....
since this is a very different question and doesn't belong to this thread i would recommend you to start a new thread regarding your NEW problem in the javascript forum ...

kind regards
MOD
Mar 27 '08 #19
acoder
16,027 Expert Mod 8TB
This is obviously a JavaScript problem thread. Moved to the JavaScript forum. Please post in the relevant forum in future.

Moderator.
Mar 27 '08 #20
malav123
217 100+
This is obviously a JavaScript problem thread. Moved to the JavaScript forum. Please post in the relevant forum in future.

Moderator.

Thanks for Suggestion...
I am using your site from several days but i was using only .net section of Forums today i opens this section... so i will follow as you suggested from today...
Mar 28 '08 #21
acoder
16,027 Expert Mod 8TB
It was addressed to the OP (kiran83), but if you benefited, you're welcome.
Mar 31 '08 #22

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

Similar topics

3
by: NotGiven | last post by:
I have a web form with several fields. If I copy & paste from a RTF document into a field, the javascript validation and field length are bypassed and cause the form to fail. Any ideas?
19
by: dmiller23462 | last post by:
Hi guys....I have absolutely NO IDEA what I'm doing with Javascript but my end result is I need two text boxes to stay hidden until a particular option is selected....I've cobbled together the...
5
by: JJ_377 | last post by:
I want a JavaScript validation function to fire on an ASP.NET textbox's change event. Here's what I've been trying and it is not working. The following added in the webform's page load event: ...
3
by: Mike P | last post by:
I have a method that I use for Javascript validation (see below). What I want to do is change the alert title, buttons, icon etc. Does anybody know the correct syntax to do this? private void...
1
by: karen987 | last post by:
I have a comment form, on a news website, ASP page, which users fill in and it adds comments to a news article. The reader clicks on a headline and the comments open up in a new window. It already...
1
by: ll | last post by:
Hi, I am working with a page that has both cfform elements and 'plain html' form elements. In particular, I am needing to validate my textarea form field and my email text field. On one of my...
1
by: shrin | last post by:
Hi all, I want to use asp.net validator and javascript validation function on a single form for different fields. also I want to execute some code on button click after the validation is completed....
1
by: jerrydigital | last post by:
Hello, I have a form that i use ASP to process the form to my access database. It works well but I'm struggling to get the javascript validation to work. I have posted a small version of my form...
12
by: btreddy | last post by:
Hii Experts, im facing a problem with the javascript validation.i've a gridview in my web form and added a footer tempalte and placed textboxes in tht tempalte ,just to add a new row to the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.