Quantcast
Channel: Microsoft Dynamics CRM
Viewing all articles
Browse latest Browse all 154803

Forum Post: RE: Field validation using Javascript

$
0
0
Hi Lucas, Michel is correct , you should go the way Michel suggested. I have done little modification to reduce the redundancy of the code. Just created one reusable method where you need to pass the validation details. Hope this helps. function ValidateField() { //1. The contacts first and last name must be alphabets ([A-Z][a-z]) var _expression = /[^a-z]/ig; //2. The account names can have 8 special characters such as & , ', ", #, -, /, _expression = /[^a-z0-9&\'"#\-\/<>]/ig; //3. The city name must be alphabets ([A-Z][a-z]) _expression = /[^a-z]/ig; //4. phone number attribute can have only 0-9, -, (,) characters as a valid characters _expression = /[^0-9,\-]/ig; //5. The postal code attribute can have only 0-9, - characters as a valid characters _expression = /[^0-9\-]/ig;_ var _fieldName = 'lastname'; var _messages = 'Invalid value, please only enter letters'; validateFieldUtility(_fieldName, _expression,_messages); } function validateFieldUtility(_fieldName, _expression,_messages) { var currentValue = Xrm.Page.getAttribute(_fieldName).getValue(); if (_expression.test(currentValue)) { Xrm.Page.getControl(_fieldName).setNotification(_messages); } else { Xrm.Page.getControl(_fieldName).clearNotification(); } }

Viewing all articles
Browse latest Browse all 154803

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>