//
//  StringValidations.swift
//  WOKA
//
//  Created by MacBook Pro on 29/04/24.
//

import UIKit

// MARK: - Validation for numbers , name , name & number

extension String{
    
    func nameCharacterOnly()->Bool{
        let allowedCharacters = CharacterSet(charactersIn:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ").inverted
        let components = string.components(separatedBy: allowedCharacters)
        let filtered = components.joined(separator: "")
        if string != filtered {
            return false
        }else{
            return true
        }
    }
    
    func onlyNumber()->Bool{
        let allowedNumber = CharacterSet(charactersIn:"0123456789").inverted
        let components = string.components(separatedBy: allowedNumber)
        let filtered = components.joined(separator: "")
        if string != filtered {
            return false
        }else{
            return true
        }
    }
    
    func onlyPhoneNumber()->Bool{
        let allowedNumber = CharacterSet(charactersIn:"+0123456789").inverted
        let components = string.components(separatedBy: allowedNumber)
        let filtered = components.joined(separator: "")
        if string != filtered {
            return false
        }else{
            return true
        }
    }
    
    func onlyNumberAndDecimal()->Bool{
        let allowedNumber = CharacterSet(charactersIn:"0123456789.").inverted
        let components = string.components(separatedBy: allowedNumber)
        let filtered = components.joined(separator: "")
        if string != filtered {
            return false
        }else{
            return true
        }
    }
    
    func numberAndCharacter()->Bool{
        let allowedCharacters = CharacterSet(charactersIn:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ").inverted
        let components = string.components(separatedBy: allowedCharacters)
        let filtered = components.joined(separator: "")
        if string != filtered {
            return false
        }else{
            return true
        }
    }
    
    func numberAndCharacterAndSpecialChar()->Bool{
        let allowedCharacters = CharacterSet(charactersIn:"!@#$%^&*()+=-[]{};:'\"|<>,.?/~`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz ").inverted
        let components = string.components(separatedBy: allowedCharacters)
        let filtered = components.joined(separator: "")
        if string != filtered {
            return false
        }else{
            return true
        }
    }
    
    func userName()->Bool{
        let allowedCharacters = CharacterSet(charactersIn: "abcdefghijklmnopqrstuvwxyz0123456789-_").inverted
        let components = string.components(separatedBy: allowedCharacters)
        let filtered = components.joined(separator: "")
        if string != filtered {
            return false
        }else{
            return true
        }
    }
}
