Align landlord profile validation (#47)
This commit is contained in:
1 parent
d1cdc6eaeb
commit
66fa95dabd
13 files changed
+462
-32
No files matched your search
@@ -0,0 +1,20 @@
|
||||
export function isValidPhoneNumber(value: string): boolean {
|
||||
let compact = '';
|
||||
for (const character of value.trim()) {
|
||||
if (!' \t\n\r()./-'.includes(character)) compact += character;
|
||||
}
|
||||
if (!compact) return true;
|
||||
if (compact.length === 10 && compact[0] === '0' && digits(compact, 0)) return true;
|
||||
if (compact.startsWith('00')) compact = `+${compact.slice(2)}`;
|
||||
return (
|
||||
compact.startsWith('+') && compact.length >= 9 && compact.length <= 16 && digits(compact, 1)
|
||||
);
|
||||
}
|
||||
|
||||
function digits(value: string, start: number): boolean {
|
||||
for (let index = start; index < value.length; index += 1) {
|
||||
const character = value.charCodeAt(index);
|
||||
if (character < 48 || character > 57) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
Reference in new issue
Block a user