473,466 Members | 1,377 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Regarding atleast one character of alphabet in textbox...

15 New Member
Hello,
i have to check following things in textbox control.I need javascript for this.Can anyone help me.....

- be at least 1 character long
- contain at least 1 standard alphabetic character
- be a maximum of 40 characters including spaces (limited by text box maximum)

Thanks,
Senthilnathan.
Sep 20 '07 #1
4 2965
gits
5,390 Recognized Expert Moderator Expert
hi ...

have you tried something for your own already? post the code you already have ... you may use regEx or regular js-stringobject-methods for that ...

kind regards
Sep 20 '07 #2
senthilnathan1985
15 New Member
Hi,
I have used following code for number filteration...

Expand|Select|Wrap|Line Numbers
  1. <script language="JavaScript" type="text/javascript" >
  2. function stringFilter (sender, args)
  3.  
  4. {
  5. var s = window.event.srcElement.value;
  6.  
  7. filteredValues = "1234567890"; // Characters stripped out
  8. var i;
  9.  
  10. var returnString = "";
  11.  
  12. for (i = 0; i < s.length; i++) { // Search through string and append to unfiltered values to returnString.
  13. var c = s.charAt(i);if (filteredValues.indexOf(c) == -1)
  14.  
  15. returnString += c;
  16.  
  17. }
  18. if ( s.length != returnString.length ) {
  19.  
  20. alert('Only alphabets are allowed!');
  21. window.event.srcElement.value = returnString;
  22.  
  23. }
  24.  
  25. }
  26.  
  27. // End -->
  28.  
  29. </script>
Now i need javascript for Atleast one character should be alphabet....

Thanks,
Senthilnathan
Sep 21 '07 #3
gits
5,390 Recognized Expert Moderator Expert
you may test for length > 0 because a string is an array of characters ... have a look at the following example that uses regEx for testing and should do what you want:

Expand|Select|Wrap|Line Numbers
  1. // your input-value
  2. var txt = '788k jkjjlk';
  3.  
  4. function test_value(t) {
  5.     var val = false;
  6.  
  7.     // strip the numbers
  8.     var t1 = t.replace(/\d/g, '');
  9.  
  10.     if (/[a-z]/gi.test(t1) && t1.length > 0) {
  11.         val = true;
  12.     }
  13.  
  14.     return val;
  15. }
  16.  
  17. // in our testcase the function returns true
  18. test_value(txt);
  19.  
kind regards
Sep 21 '07 #4
gits
5,390 Recognized Expert Moderator Expert
and have a look how we can shorten the code ...

Expand|Select|Wrap|Line Numbers
  1. var txt = '788';
  2.  
  3. function test_value(t) {
  4.     var t1 = t.replace(/\d/g, '');
  5.     return (/[a-z]/gi.test(t1) && t1.length > 0);
  6. }
  7.  
  8. test_value(txt);
  9.  
here it will return false ... and only 2 lines for the check-code :) ...

kind regards
Sep 21 '07 #5

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

Similar topics

5
by: Stefan Krah | last post by:
Hello, I am currently writing code where it is convenient to convert char to int . The conversion function relies on a character set with contiguous alphabets. int set_mesg(Key *key, char...
4
by: Brian O'Haire | last post by:
Hi I am doing a project where I have to use multiple character sets for the input. They would be English, Symbol and possible Greek, These will be used as symbols for processing an algebraic...
6
by: Lucvdv | last post by:
In a sorted list, certain characters are grouped together, for example "çb" (cedille b) comes after "ca" but before "cc". Is there a built-in way to find out what 'base character', such as C for...
1
by: oraustin | last post by:
I'm looking at an MS SQL server database and it stores city names across the world. All a arabic , chinese etc names are converted to the latin alphabet. I feel it is probably critical we...
0
by: rsimlote | last post by:
I have a datagridview with 5 comboboxes. After selecting choices in the first row, when the user move on to or enter into the combobox in the next row, the selection from the previous row displays...
6
by: new2script | last post by:
Hi, I'm very new to c++. I need to write a prgrm that convert each character received into the next character in the alphabet. As a special case convert z to a. Here what I wrote so far. ...
1
by: kannabiran | last post by:
Hi, Im using C# ASP.Net here in the textbox i need to get the input as like follows ,any alphabet or any alphabet,any alphabet for example ,C or C,E like this i want to get the input.The...
6
by: borophyll | last post by:
Hi Please let me know if I have this clear. The basic source character set is the list of (96) characters that all implementations must have in their vocabulary. All other characters...
2
by: sudhashekhar30 | last post by:
hi all i am using 2 textbox in a step of wizard control.atleast one textbox should be filled among 2 textbox. how to validate this criteria. there is no button control. so not at the click of button...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.