to prevent only white spase in input

to prevent only white spase in input

azonekz@gmail.comazonekz@gmail.com Posts: 32Questions: 9Answers: 1

Hi!
I can't find solution how to to prevent only white space in input
I found:

.Field(
                        new Field("groupes.grp_nom")
                        .Validator(DataTables.Validation.Required(new ValidationOpts
                        {
                            Empty = false,
                            Message = "Champs obligatoires"

                        })))

But it accept ONLY white space.
Thanks in advance

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,650Questions: 1Answers: 10,093 Site admin

    I'm not entirely certain what you mean by white space in this case. Do you mean an empty value or space/tab/new line etc (which is what the term "white space" normally refers to in this context).

    Allan

  • azonekz@gmail.comazonekz@gmail.com Posts: 32Questions: 9Answers: 1

    I mean the whitespace character

  • allanallan Posts: 61,650Questions: 1Answers: 10,093 Site admin
    Answer ✓

    You would need to use a custom validator for that as the built in validation doesn't have an option to reject only whitespace characters.

    Allan

  • azonekz@gmail.comazonekz@gmail.com Posts: 32Questions: 9Answers: 1

    Yes, it working great like that:

    .Field(
                                new Field("groupes.grp_nom").Xss(false)                    
                                 .Validator((val, d, host) => Convert.ToString(val).Replace(" ", string.Empty).Length < 1
                                   ? "L'entrée doit comporter 1 caractère ou plus"
                                   : null
                              )
    

    Thanks Allan

This discussion has been closed.