473,327 Members | 1,976 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,327 software developers and data experts.

Username should take alphabets

Hi friends, i need to write validation for textbox(Usernme ) which should accept only alphabets. I am able throw validation that Please fill the UserName Details.Now it should throw that it accepts only alphabets.My code goes like this::

Expand|Select|Wrap|Line Numbers
  1. <tr>
  2.        <td style="width:30%" align="right">User Name :</td>
  3.        <td style="width:70%"> <input name="username" size="20" maxlength="155" value="<?php echo $username;?>"   onfocus="setVisibility('100','inline')"; onBlur="setVisibility('100','none')"> </td>
  4.      </tr>
  5. <tr>
  6.        <td align="right">Password :</td>
  7.        <td> <input name="password" type="password" size="20" maxlength="155" value="<?php echo $password;?>"   onfocus="setVisibility('100','inline')"; onBlur="setVisibility('100','none')"> </td>
  8.  
  9.        </tr>
  10.  
  11.  
  12. <script type="text/javascript">
  13.  
  14.  
  15. function validate_form ( )
  16. {
  17.     valid = true;
  18.  
  19.     if ( document.msgform.username.value == "" )
  20.     {
  21.         alert ( "Please fill the UserName Details." );
  22.         valid = false;
  23.     }
  24.     else if(document.msgform.password.value == "")
  25.     {
  26.      alert ( "Please fill the Password Details." );
  27.         valid = false;
  28.     }
  29. return valid;
  30.  
  31. }    
  32.  
  33. <td>
  34.      <td>  <input type="submit" name="submit" value="Submit"  onClick="return validate_form();"></td></div>
  35.        </td>
  36.  
  37.  
  38. </script>
  39.  
  40.  
Please can anybody tellme how to write validations for this username that it should accept only Alphabets.

Regards,
meeanji
Jun 24 '08 #1
1 2150
acoder
16,027 Expert Mod 8TB
You could use a regular expression, e.g. /^[a-z]+$/i You can use the match method of the string to test if it matches the regular expression, e.g.
Expand|Select|Wrap|Line Numbers
  1. var username = document.msgform.username.value;
  2. if (!username.match(/^[a-z]+$/i) {
  3.   // you can alert here...
  4.  
Jun 24 '08 #2

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

Similar topics

18
by: Domestos | last post by:
Hi all, How do I check in a mySQL table called 'Users' on column user_name when registering a new user_name to make sure the new 'user_name' does not already exist in that column? TIA
3
by: Newbie | last post by:
I am a newsbie to ASP but need to get a script together that will insert the Windows Username of the local machine into an access database. I get the errors from my code below, can anyone help me...
5
by: salo | last post by:
hi... can anybody help me for displaying only alphabets in textboxes in visual studio 2005 i gave in validation expression for regular expression validation...... but still im not getting ....if i...
1
by: rajeevs | last post by:
Hi I have posted earlier about the same but only one reply thanks but i dont know how to do that. Please help again i will explain what i need to do in ms access by using a query i want to trim...
3
missshaikh
by: missshaikh | last post by:
i need to make a query Sort by alphabets "D" or Sort by alphabets "E" means Sort by A B C D E F G H I J K L M N O P Q R S T U V W X Y Z All
17
nitindel
by: nitindel | last post by:
Hi All, I have a text box and want to validate it like this: I want to enter Numerics or alphanumerics in the text box but not Alphabets alone.If Alphabets alone entered then...
1
by: sury | last post by:
I want to split a word into individual alphabets and substitute a word for each of the alphabets in c#. example: If the word entered is LATE, the output wud be L:London A :Apple T:Tom E:Egg
7
by: prigupta2 | last post by:
i want to type Alphabets and numbers in text box in such a way first alphabets then number ex C102 M458 only CM0123456789 please provide code in vb6.0
4
by: rajeevs | last post by:
Hi Previously I asked this question and I got the answer from the moderator. I am getting all the alphabets, but now i want to get the alphabets before the first occurance of numeric value. I am...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.