How to Count Numbers of Attachments

Hi,
I need to count the numbers of attachments attached in the form.
is there any way?
please help.

cur_frm.attachments.get_attachments().length

Thank you very much @ashish-greycube its working.

@ashish-greycube can you please also tell me how to trigger this on when user attach files, currently it is working on refresh event.