views:

275

answers:

4

i have a validation in my .net textbox where it will take only numbers

but when i put the the phone format like

080 234234

it will not accept because of a space

how to resolve this ?

could anyone help in regular expression ?

Current expression is this [0-9]+

i want only single space ... no two spaces should be encoraged

+1  A: 
[0-9]+\s?[0-9]+

The question mark indicates there is zero or one of the preceding element.

A: 

something like this: ([0-9]{1}[0-9]*[\s]{0,1}[0-9])+([\s]{0,1}[0-9]+)

UPDATE: the benefit of this method is that it won't allow leading or trailing spaces, and of course enforces single spaces.

Irfy
+1  A: 

This will allow a single white space after the first three digits: [0-9]{3}\s?[0-9]{6}

This would allow white spaces (only one in a row) anywhere: ([0-9]\s?)+

James Conigliaro
A: 

\s gives one space. Maybe something like this: [0-9]{3}\s?[0-9]{6} This means it'll take three digitis followed by an optional whitespace character and ending with six digits.

Jonas