Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Simple Regex question

Simple Regex question

Scheduled Pinned Locked Moved C#
questionregex
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kozu
    wrote on last edited by
    #1

    I'm trying to verify if a character is a letter. Regex.IsMatch("3", "[a-zA-z]") returns TRUE when it should be FALSE. What am I doing wrong? thanx

    J L D J 4 Replies Last reply
    0
    • K kozu

      I'm trying to verify if a character is a letter. Regex.IsMatch("3", "[a-zA-z]") returns TRUE when it should be FALSE. What am I doing wrong? thanx

      J Offline
      J Offline
      Jimmanuel
      wrote on last edited by
      #2

      why not just use the char.IsLetter(char c) function?

      1 Reply Last reply
      0
      • K kozu

        I'm trying to verify if a character is a letter. Regex.IsMatch("3", "[a-zA-z]") returns TRUE when it should be FALSE. What am I doing wrong? thanx

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Apart from what Jimmanuel said, your code returns FALSE for me. regards

        1 Reply Last reply
        0
        • K kozu

          I'm trying to verify if a character is a letter. Regex.IsMatch("3", "[a-zA-z]") returns TRUE when it should be FALSE. What am I doing wrong? thanx

          D Offline
          D Offline
          Daniel Grunwald
          wrote on last edited by
          #4

          >>> Regex.IsMatch("3", "[a-zA-z]")
          false

          Works for me. There must be something else wrong with your code.

          1 Reply Last reply
          0
          • K kozu

            I'm trying to verify if a character is a letter. Regex.IsMatch("3", "[a-zA-z]") returns TRUE when it should be FALSE. What am I doing wrong? thanx

            J Offline
            J Offline
            jas0n23
            wrote on last edited by
            #5

            Ok, the following code worked for me. I created a Windows Form with a textbox control and a button. Check it out:

            using System;
            using System.Collections.Generic;
            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 button1\_Click(object sender, EventArgs e)
                {
                    if (Regex.IsMatch(textBox1.Text, @"\[a-zA-z\]") == false)
                    {
                        MessageBox.Show("false - input is numeric.");
                    }
                    else
                    {
                        MessageBox.Show("true - input is non-numeric.");
                    }
                }
            }
            

            }

            hope this helps. Jay.

            foreach( inch on Jason ) { Girlfriend.IsHappier(); }

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups