Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone...!!
How to validate User Name that should start with characters followed by underscore and then followed by characters but no special characters..

Any Suggestions

Thanks...
Posted
Comments
Devang Vaja 3-Oct-12 6:12am    
simple You can validate it by javascript Onkeypress and by keycode
http://www.expandinghead.net/keycode.html
use this link for keycodes...

1 solution

Hi, Try This. It will help u.

C#
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs ex)
        {

            string Content1 = "a_b";
            string Content2 = "a_@";
            string pattern = @"[A-Za-z]_[A-Za-z]";


            Regex.IsMatch(Content1, pattern); // will return true
            Regex.IsMatch(Content2, pattern); // will return false


        }
    }


}
 
Share this answer
 

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