hapijs / hapijs/joi

Better way of validating a certain hostname in URI

Open
#2,690 1 comment 0 reactions 0 assignees View on GitHub
feature
Dominant language
JavaScript
Stars
21.2k
Forks
1.5k
Avg merge
4h 57m
Merged PRs (30d)
14

Description

#### Support plan

* *is this issue currently blocking your project?* (yes/no): no
* *is this issue affecting a production system?* (yes/no): no

#### Context

* *node version*: 16.9.1
* *module version*: 17.4.2
* *environment* (e.g. node, browser, native): node
* *used with* (e.g. hapi application, another framework, standalone, ...): standalone
* *any other relevant information*:

#### How can we help?

This is related to https://github.com/sideway/joi/issues/1965. I am wondering if there is a way of validating whether a given URI has a certain hostname. This would be useful, for instance, to validate social media URIs (e.g., instagram, facebook, twitter). In the thread https://github.com/sideway/joi/issues/1965 it is mentioned that the portion can be verified through some new option introduced in v16, but I couldn't figure out how to do it yet. For now I am relying on regex (see example below), though one could have a custom validation step (using node URL.hostname).

```js
facebook: Joi.string()
.uri({
scheme: 'https',
domain: {
// is there a way of checking the hostname here?
}
})
.regex(/https:\/\/(www\.)?facebook\.com\/.*/)
.optional(),
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.