Thursday 22 January 2015

Jogendra Singh

In iOS form Phone number validation in swift language


Simple phone number validation in swift ios 8 , Using this function  you can easily  check phone number . Also have some example for this using NSPredicate etc

you can see lots of method for number validation. But I made this sort method


    func phoneNumberValidation(value: String) -> Bool {
        var charcter  = NSCharacterSet(charactersInString: "0123456789").invertedSet
        var filtered:NSString!
        var inputString:NSArray = value.componentsSeparatedByCharactersInSet(charcter)
        filtered = inputString.componentsJoinedByString("")
        return  value == filtered
    }

How to use this validation function in code

if    self.phoneNumberValidation(contactNumTextF.text) == false  {
            let alert = UIAlertView()
            alert.title = "Message"
            alert.message = "Enter Valid Contact Number"
            alert.addButtonWithTitle("Ok")
            alert.delegate = self
            alert.show() 
}else {
            // Number valid
         } 


You can also check this validation in Objective C Language  simple phone number validation in IPhone sdk Objective C

Thanks for Visit  , Also can visit on My blog Facebook page iPhone & iPad Application Development Help World and also can visit Google+ 

Jogendra Singh

About Jogendra Singh -

I'm Founder of Jogendra.Com. I love to share my bright ideas with the whole blogging community. I'm a good iPhone Application Developer. Apart from Blogging, I love to play Cricket and mobile games (Clash of clans).

Subscribe to this Blog via Email :