Skip to content
Snippets Groups Projects
Commit a5b8b690 authored by Tore.Brede's avatar Tore.Brede
Browse files

Removing some unintentional formatting changes

parent ddd26aa0
No related branches found
No related tags found
1 merge request!88GREG-60: Validate e-mail
Pipeline #95865 failed
import validator from '@navikt/fnrvalidator' import validator from '@navikt/fnrvalidator'
import i18n from 'i18next' import i18n from 'i18next'
import { isValidPhoneNumber } from 'libphonenumber-js' import {isValidPhoneNumber} from 'libphonenumber-js'
const valid_email_regex = /^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+(\.[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/ const valid_email_regex = /^(?=.{1,254}$)(?=.{1,64}@)[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+(\.[-!#$%&'*+/0-9=?A-Z^_`a-z{|}~]+)*@[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?(\.[A-Za-z0-9]([A-Za-z0-9-]{0,61}[A-Za-z0-9])?)*$/
export function getCookie(name: string) { export function getCookie(name: string) {
if (!document.cookie) { if (!document.cookie) {
return null return null
} }
const cookies = document.cookie const cookies = document.cookie
.split(';') .split(';')
.map((c) => c.trim()) .map((c) => c.trim())
.filter((c) => c.startsWith(`${name}=`)) .filter((c) => c.startsWith(`${name}=`))
if (cookies.length === 0) { if (cookies.length === 0) {
return null return null
} }
return decodeURIComponent(cookies[0].split('=')[1]) return decodeURIComponent(cookies[0].split('=')[1])
} }
export function maybeCsrfToken() { export function maybeCsrfToken() {
const csrfToken = getCookie('csrftoken') const csrfToken = getCookie('csrftoken')
if (!csrfToken) { if (!csrfToken) {
return null return null
} }
return { return {
'X-CSRFToken': csrfToken, 'X-CSRFToken': csrfToken,
} }
} }
export function postJsonOpts(data: object): RequestInit { export function postJsonOpts(data: object): RequestInit {
return { return {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
...maybeCsrfToken(), ...maybeCsrfToken(),
}, },
body: JSON.stringify(data), body: JSON.stringify(data),
credentials: 'same-origin', credentials: 'same-origin',
} }
} }
export function isValidFnr(data: string | undefined): boolean | string { export function isValidFnr(data: string | undefined): boolean | string {
if (data === null) { if (data === null) {
return i18n.t<string>('common:validation.invalidIdNumber') return i18n.t<string>('common:validation.invalidIdNumber').toString()
} }
const valid = validator.idnr(data as string).status === 'valid' const valid = validator.idnr(data as string).status === 'valid'
if (valid) { if (valid) {
return true return true
} }
return i18n.t<string>('common:validation.invalidIdNumber') // TypeScript complains if toString is not used on the function result
return i18n.t<string>('common:validation.invalidIdNumber').toString()
} }
export function isValidMobilePhoneNumber(data: string | undefined): boolean | string { export function isValidMobilePhoneNumber(data: string | undefined): boolean | string {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment