Click here to Skip to main content
13,298,731 members (46,505 online)
Rate this:
Please Sign up or sign in to vote.
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

Posted 3-Oct-12 0:46am
Devang Vaja 3-Oct-12 6:12am
simple You can validate it by javascript Onkeypress and by keycode
use this link for keycodes...

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Hi, Try This. It will help u.

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()
        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



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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171207.1 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100