Search code examples
grailsgrails-orm

How to store a textfield without containing blanks in grails


I enter the field IBAN with length 27 as

xxxx xxxx xxxx xxxx xxxx xx

in my view.

The IBAN field in the database has length 22.

How can I cut off the blanks that I get from the view, before the field is stored to the database ?

Peter


Solution

  • One way to do it is in the controller. You can replace the blank spaces using the Java String replaceAll() Method.

    Example:

      String replaceString=s1.replaceAll(" ","");//replaces all blanks spaces  
    

    Documentation:

    replaceAll(String regex, String replacement)

    Replaces each substring of this string that matches the given regular expression with the given replacement.

    https://docs.oracle.com/javase/7/docs/api/java/lang/String.html