Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Oh my god today am like bottlenecked since am fresh developer :(

please help some

I need to validate username .that should allow only alpha numeric and Email id also can be username

how can i use this both validation together

Thanks
Posted
Updated 31-May-12 18:55pm
v2

Hi

You can write this JavaScript Function nd then call it on Textbox event

JavaScript
<script type="text/javascript" language = "javascript">
 function Check(e)
    {
     var unicaode = e.charcode ? e.charcode : e.KeyCode 
 if (!((unicaode >= 48 && unicaode <= 57) || (unicaode = 64) || (unicaode >= 65 && unicaode <= 90) || (unicaode = 95) || (unicaode = 46) || (unicaode >= 97 && unicaode <= 122) ))
           {
     alert('Invalid character');
         return false;
         }
       else 
       {
         return true;
       }
     
    }
 </script>


And call it on TextBox event

ASP.NET
<asp:textbox id="txtInput" runat="server" style="position :absolute " onkeypress="return Check(event)" xmlns:asp="#unknown"></asp:textbox>


Thank You
 
Share this answer
 
Comments
kimberly wind 5-Jun-12 2:45am    
this script not working again it allows only alpha numeric not allowing any Emailid (@._-) this character alone must accept but its not accepting
Vedangi 5-Jun-12 2:50am    
Ok. You can try Regular Expression allowing (@._-) characters .
kimberly wind 5-Jun-12 2:54am    
that's what my question here ..How to use that in MVC3 Razor Engine
Yes, You can use both Required Field validator and Regular Expression Validators for these.

Thanks.
 
Share this answer
 
v2
Comments
kimberly wind 5-Jun-12 3:12am    
hello am asking about how to use that help on that

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900