2 changed files with 15 additions and 4 deletions
			
			
		| @ -1,12 +1,22 @@ | |||||
| import { AbstractControl, ValidationErrors } from '@angular/forms'; | import { AbstractControl, ValidationErrors } from '@angular/forms'; | ||||
| import * as IPCIDR from 'ip-cidr'; | import * as IPCIDR from 'ip-cidr'; | ||||
|  | import {Address4, Address6} from 'ip-address' | ||||
| 
 | 
 | ||||
| export class IPValidator { | export class IPValidator { | ||||
| 
 | 
 | ||||
|   static isIPAddress(control: AbstractControl): ValidationErrors | null { |   static isIPAddress(control: AbstractControl): ValidationErrors | null { | ||||
|     if (!control.value  || !(new IPCIDR(control.value).isValid())) { | 
 | ||||
|       return { validIP: true }; |     try { | ||||
|     } |       new Address4(control.value) | ||||
|     return null; |       return null | ||||
|  |     } catch (e) {} | ||||
|  |     try{ | ||||
|  |       new Address6(control.value) | ||||
|  |       return null | ||||
|  |     } catch (e) {} | ||||
|  |     return { validIP: true }; | ||||
|   } |   } | ||||
|  | 
 | ||||
|  | 
 | ||||
|  | 
 | ||||
| } | } | ||||
|  | |||||
					Loading…
					
					
				
		Reference in new issue