Click here to Skip to main content
12,630,410 members (28,914 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 3-Oct-12 0:46am
cunny301
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

Rate this: bad
 
good
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()
        {
            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

 
        }
    }
 

}
  Permalink  

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 | Mobile
Web02 | 2.8.161205.3 | Last Updated 3 Oct 2012
Copyright © CodeProject, 1999-2016
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