Skip to main content
Inspiring
Oct 7, 2025 7:43 PM UTC
Question

Do not allow whitespace only in textfield validation

I have a textField that I do not want users to be able to enter in a space unless it is a part of the case number.

For example, users should not be able to enter this: 

But if there are spaces in the case number, then it should be allowed

I've tried regexmatch, I've tried a if / isnullorempty statement 

example: 

if(
 a!isNullOrEmpty(ri!notice),
  "Case Number is invalid.",
    null()
)

6 replies

mikes0011
Brainy
Oct 7, 2025 9:05 PM UTC

trim your input at save time.

a!textField(
  label: "notice",
  value: ri!notice,
  saveInto: a!save(ri!notice, trim(save!value))
)

The Expression Guru
Inspiring
Oct 7, 2025 9:10 PM UTC

Im looking to also display an error message if there is empty spaces :(

mikes0011
Brainy
Oct 7, 2025 9:22 PM UTC

You can only display an error message when a string is entered.  So you can choose either to trim the input (thus not allowing only blank space to be entered), or you can use a validation that shows up when removing all blanks would result in a null.

validations: {
 if(
  a!isNullOrEmpty(trim(ri!notice)),
  "don't enter only blank spaces",
  null()
 )
}

The Expression Guru
shubhama926776
Brainy
Oct 8, 2025 5:20 AM UTC

You try this below code

a!localVariables(
  local!caseNumber,
  a!textField(
    label: "Case Number",
    labelPosition: "ABOVE",
    saveInto: local!caseNumber,
    placeholder: "Enter Case Number",
    refreshAfter: "UNFOCUS",
    value: local!caseNumber,
    validations: {
      if(
        or(
          a!isNullOrEmpty(local!caseNumber),
          len(trim(local!caseNumber)) = 0
        ),
        "Case Number is invalid.",
        null()
      )
    }
  )
)

शुभम्
mikes0011
Brainy
Oct 8, 2025 7:34 PM UTC

Just an FYI - while this won't cause an error or anything, the null check in the validation message here is not useful, as all field validations (i.e. things in the "validations" parameter, as opposed to "required" validations which are configured separately) do not fire under any circumstances when the field's value is null.  Hence the validation configuration I already suggested above.

The Expression Guru
Inspiring
Oct 8, 2025 7:35 PM UTC

Thank you for all your help as always!