Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpha Space #1191

Open
shamir92 opened this issue Nov 9, 2023 · 4 comments
Open

Alpha Space #1191

shamir92 opened this issue Nov 9, 2023 · 4 comments

Comments

@shamir92
Copy link

shamir92 commented Nov 9, 2023

  • [true ] I have looked at the documentation here first?
  • [ true] I have looked at the examples provided that may showcase my question here?

Package version eg. v9, v10: v10

Issue, Question or Enhancement:

Alpha validator cannot have space. I think we need it.

Code sample, to showcase or reproduce:

	hasPass := regexp.MustCompile(`^[a-zA-Z ]+$`).MatchString(reqData.Name)
@trungdlp-wolffun
Copy link

I custom validator @shamir92

var regexAlphaNumSpace = regexp.MustCompile("^[ \\p{L}\\p{N}]+$")

var Ins   *validator.Validate

func init() {
  Ins = validator.New()
  Ins.RegisterValidation("alphanumspace", ValidateAlphaNumSpace)
}

func ValidateAlphaNumSpace(fl validator.FieldLevel) bool {
  return regexAlphaNumSpace.MatchString(fl.Field().String())
}

Use:

type Request struct {
  Name string `json:"name" validate:"required,alphanumspace"`
}

@zemzale
Copy link
Member

zemzale commented Jan 12, 2024

Changing the current validator would be a breaking change.

But I can see benefit for such a validator so feel free to open a PR for that

@nic6200
Copy link

nic6200 commented Jan 28, 2024

Hi @zemzale. Can I add a new validation for alpha spaces?

@krobitaille-stash
Copy link

Would love this but I think the regex should be modified so only whitespace isn't valid?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants