c# regular expression

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Peted

    c# regular expression


    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

  • =?Utf-8?B?RXRoYW4gU3RyYXVzcw==?=

    #2
    RE: c# regular expression

    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" wrote:
    >
    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
    >
    >

    Comment

    • =?ISO-8859-1?Q?Arne_Vajh=F8j?=

      #3
      Re: c# regular expression

      Peted wrote:
      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

      Comment

      • Peted

        #4
        Re: c# regular expression


        Cheers,

        i will give it a go thanks

        Peted


        On Mon, 28 Apr 2008 22:22:05 -0400, Arne Vajhøj <arne@vajhoej.d k>
        wrote:
        >Peted wrote:
        >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

        Comment

        • p0rk jell0

          #5
          RE: i will give it a go thanks

          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...

          Comment

          Working...