473,568 Members | 2,939 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Check for blank space as first character and trimming textbox i/p

3 New Member
Hello all,

I have a textbox, in which i have to perform the following validations

1)first character cannot be blank space
2)characters should not exceed 100
3)if exceeded 100, it should trim the i/p to 100 characters

How can i do it?
Please give your valuable suggestions

Thank you all
Sep 24 '10 #1
4 15314
RamananKalirajan
608 Contributor
Hi Divyanshi,
get the textbox content in a variable and check with the two properties as shown below

Ex:
Expand|Select|Wrap|Line Numbers
  1.    var txt = document.getElementById('textBox').value;
  2.    if(txt.charAt(0)==' '){
  3.      //what should be done for space
  4.    }
  5.    if(txt.length>100){
  6.      //what should be done when the text content is more than 100 char
  7.    }
Thanks and Regards
Ramanan Kalirajan
Sep 24 '10 #2
Dormilich
8,658 Recognized Expert Moderator Expert
regarding 2), limit the textbox to 100 chars using the maxlength attribute
Sep 24 '10 #3
Divyanshi
3 New Member
I tried the following

Expand|Select|Wrap|Line Numbers
  1. function validateDetails()
  2. {
  3.   var TDetails=document.getElementById('<%=txtGDetails.ClientID %>').value;
  4.   if(TDetails=="")
  5.   {
  6.   alert("Please Enter Details");
  7.   document.getElementById('<#=txtGDetails.ClientID').focus();
  8.   return false;
  9.   }
  10.   var count = document.getElementById ('<%=txtGDetails.clientID %>').value.length;
  11.   var txt = document.getElementById('<%=txtGDetails.ClientID %>').value;
  12.   if (count >= 250)
  13.   {
  14.     alert("Details should not exceed 250 characters");
  15.     document.getElementById('<#=txtGDetails.ClientID').focus();
  16.     return false ;
  17.   }
  18.    if (txt.charAt(0)=='')
  19.    {
  20.    alert("First space cannot be blank");
  21.    return false ;
  22.   }    return true ;
  23.    } 
It seems not working, still if i give space as first character, it is not giving the message

And also if the character is more than 250, it has to delete the remaining text

Please help to get this done

Thanks
Sep 24 '10 #4
RamananKalirajan
608 Contributor
Hi,
For your first problem pls find a working sample below
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function checkSpace(){
  5.   var val = document.getElementById('myText').value;
  6.   if(val.charAt(0)==" "){
  7.     alert("I am found")
  8.   }
  9. }
  10. </script>
  11. </head>
  12. <body>
  13.  <input type="text" name="myText" id="myText" value=" " />
  14. <input type="button" value="Check Space" onclick="checkSpace();"/>
  15. </body>
  16. </html>
For your second problem use the substring()

Thanks and Regards
Ramanan Kalirajan
Sep 27 '10 #5

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

Similar topics

2
1968
by: Gary | last post by:
Morning all, I have a form field called: Bsk01 How do I onBlur prompt the user to enter a ZERO as character one, if one is not already entered. At the same time, I would like to ensure at least 5t characters have been entered. This validation should also only trigger if anything is entered. Basically, if the user chooses to enter...
2
37128
by: barb28 | last post by:
Hello, sometimes I have noticed that in web addresses, the number: 20% will show up in the address. I think this is somehow related to a 'blank space', but am unsure, does anyone know about this? I have seen it mostly I think with netscape,
0
2273
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 C C X M L M C C P B C E U U R E U S R R E
2
2225
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 columns. I perform regular expression validations in the EditItemTemplate for the fields that require such validation. The datagrid is inside a div...
2
9164
by: coolvixs | last post by:
hi, i have some data in mysql in a column like this: 6.1.01 Financial Regulations 3.32.02 Academic Counseling what iam selecting is select by letter A, B, C...Z. so my first char in the column is always a integer, how can i select when the first few characters are always a integer, i want to get rid of the integers and run query on the...
12
1640
by: Frank | last post by:
There must be an easier way then what I'm doing to determine if the first character in a string is a valid letter. My code is getting to big. There must be a better way. Thanks in advance
4
1583
by: cyberlei | last post by:
like user have to type "A" for the first character in the blank bar,so how can i restrict the "A" for the first character in php string? Thank you
5
4726
by: plsHelpMe | last post by:
Hi Frens, I want to show a blank space at the begining of the option tag using javascript, can anyone please help me for the same. Let me explain what i want: I want to have an event which the following code will give <Select> <option>&nbsp;option1</option> <option>option2</option> </select>
0
7693
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7604
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7916
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8117
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7962
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6275
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
2101
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.