logo
down
shadow

Check if string contains special characters in Swift


Check if string contains special characters in Swift

By : robin2150
Date : November 19 2020, 12:41 AM
will be helpful for those in need Your code check if no character in the string is from the given set. What you want is to check if any character is not in the given set:
code :
if (searchTerm!.rangeOfCharacterFromSet(characterSet.invertedSet).location != NSNotFound){
    println("Could not handle special characters")
}
let regex = NSRegularExpression(pattern: ".*[^A-Za-z0-9].*", options: nil, error: nil)!
if regex.firstMatchInString(searchTerm!, options: nil, range: NSMakeRange(0, searchTerm!.length)) != nil {
    println("could not handle special characters")

}
let searchTerm = "a+b"

let characterset = NSCharacterSet(charactersInString: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
if searchTerm.rangeOfCharacterFromSet(characterset.invertedSet) != nil {
    print("string contains special characters")
}
let characterset = CharacterSet(charactersIn: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
if searchTerm.rangeOfCharacter(from: characterset.inverted) != nil {
    print("string contains special characters")
}


Share : facebook icon twitter icon
How to check input string with no spaces & special characters except two special charaters (that is & and Ñ)

How to check input string with no spaces & special characters except two special charaters (that is & and Ñ)


By : Anup Biswas Pulak
Date : March 29 2020, 07:55 AM
hope this fix your issue Actually I am done with the validation with Jquery alphanumeric plugin
i.e "$('#txtId').alphanumeric({ allow: "&Ñ" });".
Check Java String containing one alpha & numeric characters and one of these special characters(@, #,$)

Check Java String containing one alpha & numeric characters and one of these special characters(@, #,$)


By : Souf Iane
Date : March 29 2020, 07:55 AM
I wish did fix the issue. Hi i want to check whether a string contains one alpha, one numeric and at least one of these special characters(@, #,$). So could anyone please guide me to resolve the issue. , Here is a simple implementation.
code :
private static boolean isValidPassword(char[] password) {
    boolean hasLetter = false, hasDigit = false, hasSpecial = false;
    for (char ch : password)
        if (Character.isLetter(ch))
            hasLetter = true;
        else if (Character.isDigit(ch))
            hasDigit = true;
        else if ("@#$".indexOf(ch) != -1)
            hasSpecial = true;
    return (hasLetter && hasDigit && hasSpecial);
}
How to check two string have same characters including special characters

How to check two string have same characters including special characters


By : Siva Kumar
Date : March 29 2020, 07:55 AM
wish help you to fix your issue I have two question , using a while loop seems a reasonable solution:
code :
var str1 = "ansar@#//1";
var str2 = "@#//sanra12";

s1 = str1.split('');

s2 = str2.split('');


var i = s1.length + 1;
while (i--) {
  if (s2.indexOf(s1[i]) >= 0)
    s2.splice(s2.indexOf(s1[i]), 1);
}

console.log(s2)
javascript check if string contains only alphanumeric characters + other special characters

javascript check if string contains only alphanumeric characters + other special characters


By : Don B
Date : March 29 2020, 07:55 AM
like below fixes the issue I have found this function to check if a string only contains alphanumeric characters: , You can try something like this:
code :
/^[a-z0-9-\'_\.,:\(\)&\[\]\/+=\?#@ \xC0-\xFF]+$/i
/^[^!~`\>\<]$/gi
Special Characters with Swift(Fixed check bottom of the main post)

Special Characters with Swift(Fixed check bottom of the main post)


By : K Sam
Date : March 29 2020, 07:55 AM
it should still fix some issue The problem is htmlentities() function. It converts all applicable characters to HTML entities. http://php.net/manual/en/function.htmlentities.php
It does not prevent SQL injection. So you don't need it. You can look this. How can I prevent SQL injection in PHP?
code :
if (!$this->conn->set_charset("utf8")) {
    printf("Error loading character set utf8: %s\n", $this->conn->error);
    exit();
} else {
    printf("Current character set: %s\n", $this->conn->character_set_name());
}
Related Posts Related Posts :
  • Unclear about releasing CFDictionaryRef
  • CordovaError: Promise rejected with non-error: Error code 65
  • How to append NSMutable strings into a UILabel
  • CustomCell label value does not change
  • Display ad in iAd Bannerview iAd Network
  • Warning: "Could not get traitsetID for iPhone11,6" (Assets.xcassets)
  • Changing root view controller after iOS app has loaded.
  • SocketRocket and iOS certificate pinning
  • Draggable UIButton Snap To a Circle Path
  • Running FireBase in the background
  • resizing UIPopoverController to fit UITableController
  • UICollectionView Exception Crash
  • targeting iOS5 - will it work on iOS6 also?
  • FBLoginView get email
  • Scale UIImages height to UIImageView height
  • Creating a custom progress indicator in ios
  • NSRunLoop API difference
  • Is it possible to inject custom settings into my iOS application "Notifications" settings dialog?
  • UIAlertview not accepting string as message
  • Axis change of stackView giving layout error
  • How to use AVAssetResourceLoader?
  • How to write block definition using properties?
  • iOS connect/reconnect to Bluetooth device when using external-accessory and MFi
  • Saving XMPP Multi User chat messages through XMPP MessageArchiving in iOS
  • Deciding iOS version: pros and cons
  • iOS: Resigned app cannot access keychain through security API
  • How can I set To and Subject fields in an E-Mail being sent by UIDocumentInteractionController?
  • Updating uilabel in view controller underneath another
  • Maximum time Intervel for NSTimer
  • Delete Core Data Entry from Table View Controller
  • How to unload UIViewcontroller from memory?
  • Compressing UIImage as Far as Possible?
  • Optimizing workflow to update internally owned cocoapods dependencies?
  • Formatting an NSDate with Abbreviated Month/Day Names
  • I'm creating a quiz game with 4 answers and I want to add score
  • Tap Gesture to Hide Navigation Bar, Tab Bar, and Status Bar
  • FBSessionStateClosedLoginFailed when I am logged in through Settings
  • CGRect positioning according to center point
  • iOS: Update table view datasource with animations without core data
  • iOS : Where to start for AliPay integration?
  • Routing App Coverage File missing but not needed?
  • Drawing on a zoomable view
  • Append NSStrings and NSNumber to NSMutableArrays and make NSMutable dictionary
  • Terminating app due to uncaught exception 'NSRangeException' when calling dequeueReusableCellWithReuseIdentifier:forInde
  • Collision without physics (Cocos2D + Box2D iOS)
  • Creating a percentage based iOS layout
  • Update tableView row from AppDelegate Swift 4
  • Assigning return value of a class method to a variable error
  • how to display circular progress in delphi ios apps?
  • I can't figure how to fix this Expected identifier or '('
  • How to Test APIs in Swift 4?
  • Link error /Build/Products/Debug-iphonesimulator file not found
  • working with a very large JSON object in iOS
  • Turn off part of the iPhone Screen
  • Phonegap 3.0 app with facebook login using xCode
  • How to add interstitial admob ads to my ios project
  • adding tapku calendar to ios app
  • Add an alertcontroller in a global swift file?
  • Take square image with Cordova (Phonegap) Camera API?
  • Amazon S3 policy allowing only upload not overwrite
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org