Resolved Using regex to restrict a textbox entry

Tucalipe

Member
Joined
Jul 7, 2017
Messages
8
Programming Experience
Beginner
I'm trying to use regex to allow only digits and a single comma on a textbox. However, all of the solutions I've found so far throw an "Unrecognized escape sequence" exception every time I try to build my project.

The last one I've tried is

C#:
        private void textBox4_Leave(object sender, EventArgs e)
        {
            if (System.Text.RegularExpressions.Regex.IsMatch(txb_Valor.Text, "(?<=^| )\d+(\.\d+)?(?=$| )"))
            {
                MessageBox.Show("Only numbers please.");
                txb_Valor.Clear();
                txb_Valor.Focus();
            }


What am I doing wrong?

EDIT.: [^0-9,] did the trick.
 
Last edited:
Back
Top Bottom