Notifications
Announcements
No record found.
Hi ,
I have "Anniversary_Year_Month" field on form having field type as text field.
want to make validation like it must follow format "YYYY-MM", otherwise prevent save and show error message window.
can i do this in CRM 2011 using javascript.
Hi,
Here is the topic about this
https://social.microsoft.com/Forums/en-US/7be7e082-7e86-4db5-97d6-da48d5f62601/dynamics-crm-2011-uk-phone-number-javascript-validation?forum=crmdevelopment
Try this function
function validateDate(context) { var txtValue = context.getEventSource().getValue(); dateRegex = /([12]\d{3}-(0[1-9]|1[0-2]))/; if (!txtValue.match(dateRegex)) { { context.getEventSource().setValue(''); event.returnValue = false; alert("The date format is incorrect"); } } }
Hi Mona,
This is the below Javascript which you call on Onchange event of "Anniversary_Year_Month" field . It give you exact match of "YYYY-MM"
function startDateFormat(){ var regs=[]; var value = Xrm.Page.getAttribute("new_startdatetext").getValue(); re = /^\d{4}\-\d{1,2}$/; if(value != ""){ if(regs = value.match(re)){ if(regs[2] < 1 || regs[2] > 12){ alert("Invalid value for month "); } if(!isNaN(regs[1])){ alert("Invalid value of Year"); } }else{ alert("not in a right format (YYYY-MM)") } }
}
Thanks for the reply.
Do i need to call this function directly onChange event of the field?
Yes, Change field name in that line
Xrm.Page.getAttribute("new_startdatetext").getValue();
and call this function on OnChnage
Go to settings->Customization->Compnent->Entities->
Go to that entity where this field is created and then go to forms->Form Properties (see below Image as I am using Updated version might you don't have same UI ) but you will get option.
on Save? it will call everytime even it is auto save or you have done any other custom code which make that record update or save.
Under review
Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.
As AI tools become more common, we’re introducing a Responsible AI Use…
We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…
These are the community rock stars!
Stay up to date on forum activity by subscribing.
Tom_Gioielli 83 Super User 2025 Season 2
Gerardo RenterÃa Ga... 49 Most Valuable Professional
#ManoVerse 40