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
4 15314
Hi Divyanshi,
get the textbox content in a variable and check with the two properties as shown below
Ex: - var txt = document.getElementById('textBox').value;
-
if(txt.charAt(0)==' '){
-
//what should be done for space
-
}
-
if(txt.length>100){
-
//what should be done when the text content is more than 100 char
-
}
Thanks and Regards
Ramanan Kalirajan
Dormilich 8,658
Recognized Expert Moderator Expert
regarding 2), limit the textbox to 100 chars using the maxlength attribute
I tried the following - function validateDetails()
-
{
-
var TDetails=document.getElementById('<%=txtGDetails.ClientID %>').value;
-
if(TDetails=="")
-
{
-
alert("Please Enter Details");
-
document.getElementById('<#=txtGDetails.ClientID').focus();
-
return false;
-
}
-
var count = document.getElementById ('<%=txtGDetails.clientID %>').value.length;
-
var txt = document.getElementById('<%=txtGDetails.ClientID %>').value;
-
if (count >= 250)
-
{
-
alert("Details should not exceed 250 characters");
-
document.getElementById('<#=txtGDetails.ClientID').focus();
-
return false ;
-
}
-
if (txt.charAt(0)=='')
-
{
-
alert("First space cannot be blank");
-
return false ;
-
} return true ;
-
}
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
Hi,
For your first problem pls find a working sample below - <html>
-
<head>
-
<script type="text/javascript">
-
function checkSpace(){
-
var val = document.getElementById('myText').value;
-
if(val.charAt(0)==" "){
-
alert("I am found")
-
}
-
}
-
</script>
-
</head>
-
<body>
-
<input type="text" name="myText" id="myText" value=" " />
-
<input type="button" value="Check Space" onclick="checkSpace();"/>
-
</body>
-
</html>
For your second problem use the substring()
Thanks and Regards
Ramanan Kalirajan
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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,
|
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
|
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...
|
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...
| |
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
|
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
|
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> option1</option>
<option>option2</option>
</select>
|
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...
|
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...
|
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. ...
| |
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...
|
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...
|
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...
|
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...
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |