TextArea Validation

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

    TextArea Validation

    I need to validate my TextArea as follows:

    1) IT SHOULD ALLOW FOR ONLY 5 COLUMNS
    2) IT SHOULD ALLOW ONLY 65 CHARACTERS PER ROW

    I need some kind of a JS validation for the same. I have tried using hard wrap
    but that doesnt help completely.

    Any help in this matter would be very much appreciated!
    Thanks!
    S Kulkarni
  • Lasse Reichstein Nielsen

    #2
    Re: TextArea Validation

    kulkarni21@hotm ail.com (Sunil Kulkarni) writes:
    [color=blue]
    > I need to validate my TextArea as follows:
    >
    > 1) IT SHOULD ALLOW FOR ONLY 5 COLUMNS[/color]

    I assume you mean rows :)
    [color=blue]
    > 2) IT SHOULD ALLOW ONLY 65 CHARACTERS PER ROW
    >
    > I need some kind of a JS validation for the same. I have tried using
    > hard wrap but that doesnt help completely.[/color]

    A regular expression should be able to match zero to five lines of
    zero to 65 characters, if you define the lines to be separated by
    newlines ("\n").

    If you want to look at automatic line wrapping, and count lines as
    they are displayed, it gets ugly fast, but with some assumptions,
    it should be manageable.

    So, let's define a line to be up to 65 characters followed by a
    newline characters, or just 65 characters followed by a newline, and
    we want to check that a string contains at most 5 lines.

    The final line can be up to 65 characters without being followed by a
    newline.

    A suitable regular expression is:
    /^(.{0,65}\n|.{6 5}){0,4}.{0,65} \n?$/

    However, the input of a textarea might not use a single character for
    newlines. Both Opera and IE ends their lines with "\x0d\x0a"
    (Carrige Return + newline, DOS EOL), where Mozilla uses "\x0a" (Just
    newline, Typical Unix EOL). Maybe Macintosh browsers use "\x0d\x0a",
    as that is the typical Apple (and Amiga) EOL sequence.

    Anyway, the above RegExp won't work in Opera and IE, since "\x0d\x0a"
    is two newline characters. The solution I can see, is to replace those
    with a single newline first:

    string.replace(/(\x0a\x0d|\x0d\ x0a)/g,"\n");

    Then test with the above RegExp.
    [color=blue]
    > Any help in this matter would be very much appreciated![/color]

    Hope this helps.
    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • DU

      #3
      Re: TextArea Validation

      Sunil Kulkarni wrote:
      [color=blue]
      > I need to validate my TextArea as follows:
      >
      > 1) IT SHOULD ALLOW FOR ONLY 5 COLUMNS
      > 2) IT SHOULD ALLOW ONLY 65 CHARACTERS PER ROW
      >
      > I need some kind of a JS validation for the same. I have tried using hard wrap
      > but that doesnt help completely.
      >
      > Any help in this matter would be very much appreciated!
      > Thanks!
      > S Kulkarni[/color]



      What's wrong with:

      <form action="">
      <p><textarea name="TextareaN ame" rows="5" cols="65"
      wrap="soft"></textarea></p>
      </form>

      The string submitted can later be rendered within a textarea with the
      same (or other) cols and rows attribute values.

      On the wrap attribute, MSDN
      Gain technical skills through documentation and training, earn certifications and connect with the community

      says:
      soft: Default. Text is displayed with wordwrapping and submitted without
      carriage returns and line feeds.
      hard: Text is displayed with wordwrapping and submitted with soft
      returns and line feeds.
      off: Wordwrapping is disabled. The lines appear exactly as the user
      types them.

      DU
      --
      Javascript and Browser bugs:

      - Resources, help and tips for Netscape 7.x users and Composer
      - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


      Comment

      • Sunil Kulkarni

        #4
        Re: TextArea Validation

        Thankyou very much for the suggestions!

        Lasse Reichstein Nielsen <lrn@hotpop.com > wrote in message news:<llspwzn0. fsf@hotpop.com> ...[color=blue]
        > kulkarni21@hotm ail.com (Sunil Kulkarni) writes:
        >[color=green]
        > > I need to validate my TextArea as follows:
        > >
        > > 1) IT SHOULD ALLOW FOR ONLY 5 COLUMNS[/color]
        >
        > I assume you mean rows :)
        >[color=green]
        > > 2) IT SHOULD ALLOW ONLY 65 CHARACTERS PER ROW
        > >
        > > I need some kind of a JS validation for the same. I have tried using
        > > hard wrap but that doesnt help completely.[/color]
        >
        > A regular expression should be able to match zero to five lines of
        > zero to 65 characters, if you define the lines to be separated by
        > newlines ("\n").
        >
        > If you want to look at automatic line wrapping, and count lines as
        > they are displayed, it gets ugly fast, but with some assumptions,
        > it should be manageable.
        >
        > So, let's define a line to be up to 65 characters followed by a
        > newline characters, or just 65 characters followed by a newline, and
        > we want to check that a string contains at most 5 lines.
        >
        > The final line can be up to 65 characters without being followed by a
        > newline.
        >
        > A suitable regular expression is:
        > /^(.{0,65}\n|.{6 5}){0,4}.{0,65} \n?$/
        >
        > However, the input of a textarea might not use a single character for
        > newlines. Both Opera and IE ends their lines with "\x0d\x0a"
        > (Carrige Return + newline, DOS EOL), where Mozilla uses "\x0a" (Just
        > newline, Typical Unix EOL). Maybe Macintosh browsers use "\x0d\x0a",
        > as that is the typical Apple (and Amiga) EOL sequence.
        >
        > Anyway, the above RegExp won't work in Opera and IE, since "\x0d\x0a"
        > is two newline characters. The solution I can see, is to replace those
        > with a single newline first:
        >
        > string.replace(/(\x0a\x0d|\x0d\ x0a)/g,"\n");
        >
        > Then test with the above RegExp.
        >[color=green]
        > > Any help in this matter would be very much appreciated![/color]
        >
        > Hope this helps.
        > /L[/color]

        Comment

        Working...