Friday, February 19, 2021

email validation with regular expressions using jquery

For email address validation there is Official Standard: RFC 5322 but the regex to match this standard is very complex and would not be suitable for implementation in our applications, but the below regex is the most appropriate to be used in our applications. I didn’t find a bug till now.

Regex:

[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:    
[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?"

Sample Javascript to validate the format of email address:

var regex = [a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*
@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?;
if(regex.test(email)){
//valid email
}

Tuesday, February 16, 2021

Versioned vs Shared vs Unversioned fields in Sitecore

 This post explains what templates and fields are in Sitecore and the differences between the Versioned, Shared and Unversioned fields in Sitecore. It also states the scope of each of these fields in different scenarios.

Templates and Fields in Sitecore

Templates will have a list fields of different types grouped into sections. So each of these templates can be used for creation of items and thus the items get all the fileds of the template which it is using.

Versioning in Sitecore

As Sitecore supports versioning of items, it also provides a list of options about the versioning of fields of items/templates. The options we have for each of the field while creating the template are Versioned, Shared, Unversioned. Let us see in detail about each of these types.

Versioned fields

By default every field in Sitecore is a versioned field. These fields can have separate language versions and several numbered versions for each language version. To mark a field as versioned do not check Shared and Unversioned checkboxes while creating the template.

Shared fields

While creating the templates, we need to check the Shared checkbox to make a field 'Shared'. The data in the Shared fields are shared among all languages and all numbered versions. So if you make a change in one language version of an item it would reflect in other languages and their numbered versions. These type of fields are used mainly if there is some data whose value need not to b versioned at all. Like a profile image or something.

SharedField in a Template

When a field is shared, it will be visible from the item using that template. Say there is an item called 'Sample Item', with a shared field 'Title', then there is a small note '[Shared]' visible beside the field in all the items which are using this template.

Sharedfield in Item

Unversioned fields

While creating the template, we need to check the Unversioned checkbox to make a field Unversioned. The data in the Unversioned fields are separate for each language version but all the numbered versions share the same data. Select this type of field if you need to maintain different data for different languages but do not need numbered versions. Like a product name field, as it could be different in different languages and you might have decided not to maintain numbered versions.

Sharedfield in Template

Similar to the shared fields, unversioned fields will also carry a small note '[Unversioned]' beside the field name.

Sharedfield in item

Unversioned, Shared fields

What if you have checked both Unversioned and Shared? - As the shared fields does not maintain language or numbered versions, if we select both 'Unversioned' and 'Shared', the fields would be acting like 'Shared' fields. So it does not make any affect checking or unchecking 'Unversioned' checkbox after selecting the 'Shared' checkbox.

Unversioned, Sharedfield in template

Fields which are marked as Shared and Unversioned will carry a small note '[Unversioned, shared]' beside the field name

Unversioned, Shared field in item

Hope it helps. Please comment your feedback and thoughts if any.