constrain a string to 30 chars java

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    #1

    constrain a string to 30 chars java

    how to constrain a string to 30 chars?
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #2
    it is not still clear to me .... plz explain me in details

    Comment

    • oll3i
      Contributor
      • Mar 2007
      • 679

      #3
      sth like


      public static final StringConstrain t FIRST_NAME_CONS TRAINT =
      new StringConstrain t("firstName" , false, 30);

      but this doesnt work for me cos eclipse highlights StringConstrain t as an error
      and i did imports

      Comment

      • oll3i
        Contributor
        • Mar 2007
        • 679

        #4
        i need to constrain the property to string of eg 30 chars

        Comment

        • oll3i
          Contributor
          • Mar 2007
          • 679

          #5
          or sth like but again i get Constraint can not be resolved to a type error
          public static Constraint FIRST_NAME = new MaxLengthConstr aint(30);

          Comment

          • sicarie
            Recognized Expert Specialist
            • Nov 2006
            • 4677

            #6
            Originally posted by oll3i
            or sth like but again i get Constraint can not be resolved to a type error
            public static Constraint FIRST_NAME = new MaxLengthConstr aint(30);
            An easy, but not quite elegant solution would be to use a while loop - while the contents are over 30, get the string, get the length of the string, test while loop again, print out a message if you want..

            JavaDoc for String class

            Comment

            • oll3i
              Contributor
              • Mar 2007
              • 679

              #7
              i solved it i wrote a little validator class

              Comment

              Working...