c# regular expression

  • Thread starter Thread starter Peted
  • Start date Start date
P

Peted

Hi

i can use the following

^([\w\.]|\s)*$

to validate a textbox input, this ensure input is limited to
Aplhanumeric characters, full stops and spaces. I have tested this and
it seems to all work, but what i cannot get to function is a way to
have the above yet prevent the textbox ONLY having spaces entered. The
regexp string above will validate input if only spaces are entered an
i dont want that

I need input resticted to that the above exp will allow, in addition,
i need to have a way to test,
IF there is input in the textbox,
(because there maybe NO input)
it is only alpha numeric, with a selection of
punctuation marks allowed and spaces allowed
and that it is NOT consist only of spaces.

Can anyone help with how i can achieve this please


thanks

Peted
 
I'm not sure how to do what you have asked using only Regular Expressions,
but I would use the string.Trim() method. Trim removes all leading and
trailing spaces and thus will remove everything is there are only spaces....

if (InputBox.Text.Trim().Length > 0)
{
// Process things
}
else
{
// Tell user they need something in the box
}

Ethan
 
Peted said:
i can use the following

^([\w\.]|\s)*$

to validate a textbox input, this ensure input is limited to
Aplhanumeric characters, full stops and spaces. I have tested this and
it seems to all work, but what i cannot get to function is a way to
have the above yet prevent the textbox ONLY having spaces entered. The
regexp string above will validate input if only spaces are entered an
i dont want that

Untested:

^[\w\s]*[\w]+[\w\s]*$

Arne
 
Cheers,

i will give it a go thanks

Peted


Peted said:
i can use the following

^([\w\.]|\s)*$

to validate a textbox input, this ensure input is limited to
Aplhanumeric characters, full stops and spaces. I have tested this and
it seems to all work, but what i cannot get to function is a way to
have the above yet prevent the textbox ONLY having spaces entered. The
regexp string above will validate input if only spaces are entered an
i dont want that

Untested:

^[\w\s]*[\w]+[\w\s]*$

Arne
 
R U Kidding??? Don't post that you'll have a go at it and leave it there. Go and have your go at it then post your results... Unreal... It is not polite to get your answers then not share... Other people are looking at this too...
 
Back
Top