Eduardo Spagna
Eduardo Spagna

Reputation: 39

How to validate regex using the bolt compiler

I am trying to validate a field that will receive a URL. I need to validate it using an appropriate regex, but what I got from the Firebase documentation itself is not working. The compiler bolt neither compiles, causing the error:

bolt:37:3: Invalid property or method: 'validate() { this.test((/^(ht|f)tp(s?):\\/\\/[0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*((0-9)*)*(\\/?)([a-zA-Z0-9\\-\\.\\?\\'.
bolt:37:3: Invalid property or method: '\\'\\/\\\\+&=%\\$#_]*)?$/) '.
bolt: Fatal errors: 2
My code:
type Category {
  categoryName: String,
  isAvailable: Boolean,
  createdAt: Number,
  photoUrl: LinkURL,
  subcategories: Object | Null
}

type LinkURL extends String {
  validate() { this.test((/^(ht|f)tp(s?):\\/\\/[0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*((0-9)*)*(\\/?)([a-zA-Z0-9\\-\\.\\?\\,\\'\\/\\\\+&=%\\$#_]*)?$/) }
}

Upvotes: 0

Views: 101

Answers (1)

Sean Schoeman
Sean Schoeman

Reputation: 34

I believe you have an extra "(" at the start of the regex

try this

type LinkURL extends String {
  validate() { this.test(/^(ht|f)tp(s?):\/\/[0-9a-zA-Z]([-.\\w]*[0-9a-zA-Z])*((0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&=%\$#_]*)?$/) }
}

Upvotes: 0

Related Questions