Search code examples
regexcharacterrestrict

How to limit entry to just 0-9, space and comma in an ASP.net textbox


Please I can't get this to work: I have tried other solutions from here

<asp:TextBox ID="txtNumber" 
   onkeyup="this.value = this.value.replace(/^[0-9 ,]+$/, '')" 
   runat="server"
   Width="250px" 
   ToolTip="You may enter multiple numbers separated by comma"
   Wrap="False"
   placeholder="Enter phone numbers separated by comma">
</asp:TextBox>

I want to limit entry to 0-9, space and comma in an ASP.net textbox


Solution

  • You have to use negated set if you are replacing.. try this: [^0-9 ,]+$

    This will reset the textbox if invalid entry is found. (Assuming this is what you are trying)