Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Validate textfield with special character

In my app. I want to validate textfield with Special characters,

Ex. if user press the ? from keypad than user not able to enter the ? in Textfield,

Please any one suggest, How can i do that?

like image 873
Anki Avatar asked Apr 18 '12 07:04

Anki


People also ask

How do you validate special characters in HTML?

click(function(){ var fn = $("#folderName"). val(); var regex = /^[0-9a-zA-Z\_]+$/ alert(regex. test(fn)); }); }); This return false for special chars and spaces and return true for underscore, digits and alphabets.

How do you validate a special character in Javascript?

To check if a string contains special characters, call the test() method on a regular expression that matches any special character. The test method will return true if the string contains at least 1 special character and false otherwise.


1 Answers

Try like below it will help you.It will accept only letters

   - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
    {
        //For avoiding user to enter non digital number..
        if([[string stringByTrimmingCharactersInSet:[[NSCharacterSet letterCharacterSet] invertedSet]] isEqualToString:@""])
        {
            return NO;
        }
        else
        {
            return YES;
        }
    }
like image 193
Narayana Avatar answered Oct 17 '22 02:10

Narayana