<script src="http://code.angularjs.org/angular-1.0.1.js"></script>
<div ng-controller="MyCtrl">
<label>Enter your text here to check for non-breaking space: </label>
<br/>
<input type="text" ng-model="myText" ng-change="checkForNonBreaking()" style="width: 80%;" />
<br/>
<div ng-show="isNonBreakingPresent" style="color: red; font-weight: bold;">
Non-Breaking Character has been detected
<button ng-click="replaceNonBreakingCharacters()">
Remove Non-Breaking Spaces
</button>
</div>
<div ng-hide="isNonBreakingPresent">
No Non-Breaking Space is present
</div>
</div>
JavaScript
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
$scope.isNonBreakingPresent = false;
$scope.checkForNonBreaking = function() {
var positions = "";
$scope.isNonBreakingPresent = false;
for (var i = 0, len = $scope.myText.length; i < len; i++) {
if ($scope.myText[i] === '\xa0') {
positions += i + ", ";
$scope.isNonBreakingPresent = true;
}
}
if (positions.length > 1)
alert("Non-breaking space detected at position: " + positions);
}
$scope.replaceNonBreakingCharacters = function() {
var replaced = $scope.myText.replace(/\xa0/g, ' ')
$scope.myText = replaced;
$scope.checkForNonBreaking();
}
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.