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

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

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 15258
RamananKalirajan
608 512MB
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 Expert Mod 8TB
regarding 2), limit the textbox to 100 chars using the maxlength attribute
Sep 24 '10 #3
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 512MB
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
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...
2
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...
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: 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...
2
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...
12
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
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
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...
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...
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
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,...
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.