php


How to validate an angularjs in textbox?


Why is my ng-pattern in textbox of name is allowing special characters?
This is the view file:
<div ng-repeat="s in config.students">
<div class="form-group">
<label class="control-label col-lg-2"></label>
<div class="col-lg-5">
<input type="text" class="form-control" name="students[]" ng-trim="false" ng-model="class.students[$index]" required ng-pattern="/^[a-zA-Z]*$/">
</div>
<div class="col-md-5">
<button class="btn btn-danger btn-sm" ng-click="removeStudent($index)" type="button">X</button>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2"></label>
<div class="col-lg-4">
<button type="submit" class="btn btn-primary btn-grad btn-rect">Submit</button>
Cancel
</div>
</div>
ng-pattern alone will not prevent a user from entering certain text into a textbox. If you want to do that, you'll need to use a custom attribute directive on the <input>.
ng-pattern is meant to be used in conjunction with AngularJS' form validation, you can use it to hide/show validation messages and to validate a form before it is submitted.
AngularJS form validations requires unique name for each input field in the form.
But in your case you are using the same name for all the input fields in ng-repeat.
So change your input to add unique name for input in each iteration using $index
<input type="text" class="form-control" name="students{{$index}}" ng-trim="false" ng-model="class.students[$index]" required ng-pattern="/^[a-zA-Z]*$/">
Here is the Plunker.

Related Links

foreach loop not generating the right html table
ActiveMQ not returning message when queue has n number of pending messages
How do I store two eloquent models from one form?
PDO, was the query done correctly?
random function generate 2 long string the same, is it bad luck or rand() is not random?
How to get the property of stdClass php
AJAX PHP Upload file to database
Class 'Pheanstalk_Pheanstalk' not found in Laravel 4 with Beanstalk
Magento image not showing correctly
Transparent change value of return value via ORM
Fetch Combobox with Directory Name Order by Desc Order
refresh table in page when hitting the save button without refreshing the whole page
Get all session data in zend 1.12
Apple JSON API not decoding properly in PHP [closed]
Passing 20+ arguments into a function
how do i create an array of links with simple dom and php

Categories

HOME
elasticsearch
webview
redmine
plaid
braintree
visual-studio-2010
histogram
liferay-7
qooxdoo
amp
material-components
share
impala
hspi
xamarin-zebble
cqrs
buffer
jquery-select2-4
pywinauto
tomcat8
asciimath
robolectric
renderscript
significance
raml
bluemix-mobile-services
jitsi
fluent-migrator
cellular-network
morris.js
uri
background-color
offline-caching
history.js
basic-authentication
mdns
dotcms
instructions
vcenter
seafile-server
listjs
directfb
xerces-c
wdk
runtimeexception
eclipse-gmf
xll
linq.js
imgur
ejml
yoast
virtual-memory
permission-denied
dredd
image-registration
ol3-google-maps
head.js
node-apn
android-mediarecorder
polymaps
fitbit
logical
dcount
gcloud-node
eclemma
qpixmap
noclassdeffounderror
exists
mathnet
distributed-cache
mercurial-extension
persistent-object-store
accessibilityservice
i2b2
helm
arbre
chicagoboss
nastran
android-studio-import
wso2ml
tree-structure
scala-macros
baseadapter
nhibernate-criteria
comctl32
device-admin
dmake
producer
inputbox
webmethod
otl
commenting
pageviews
iosched
ctp
dynamic-rdlc-generation
dibs
asp.net-mvc-3-areas
chefspec
dojo-1.9
word-frequency
first-class
platform-independent
background-repeat
snackjs
simile
nsconnection
bll
qcar-sdk
aptitude
yahoo-maps
firephp
3270
objectinstantiation
isapi-redirect

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App