Saturday, April 9, 2011

PagedCollectionView Class MSDN Page

Expand

PagedCollectionView Class

Silverlight
Represents a view for grouping, sorting, filtering, and navigating a paged data collection.
System.Object
  System.Windows.Data.PagedCollectionView

Namespace:  System.Windows.Data
Assembly:  System.Windows.Data (in System.Windows.Data.dll)
public sealed class PagedCollectionView : ICollectionView, 
 IEnumerable, INotifyCollectionChanged, IPagedCollectionView, IEditableCollectionView, INotifyPropertyChanged
The PagedCollectionView type exposes the following members.
  NameDescription
Public method PagedCollectionView(IEnumerable) Initializes a new instance of the PagedCollectionView class.
Public method PagedCollectionView(IEnumerable, Boolean, Boolean) Initializes a new instance of the PagedCollectionView class and specifies whether the data is sorted and in group order.
Top
  NameDescription
Public property CanAddNew Gets a value that indicates whether a new item can be added to the collection.
Public property CanCancelEdit Gets a value that indicates whether the collection view can discard pending changes and restore the original values of an edited object.
Public property CanChangePage Gets a value that indicates whether the PageIndex value can change.
Public property CanFilter Gets a value that indicates whether this view supports filtering by way of the Filter property.
Public property CanGroup Gets a value that indicates whether this view supports grouping.
Public property CanRemove Gets a value that indicates whether an item can be removed from the collection.
Public property CanSort Gets a value that indicates whether this view supports sorting.
Public property Count Gets the number of records in the view after filtering, sorting, and paging.
Public property Culture Gets or sets the cultural information for any operations of the view that might differ by culture, such as sorting.
Public property CurrentAddItem Gets the item that is being added when an AddNew transaction is in progress.
Public property CurrentEditItem Gets the item in the collection that is being edited when an EditItem transaction is in progress.
Public property CurrentItem Gets the current item in the view.
Public property CurrentPosition Gets the ordinal position of the CurrentItem in the view, which might be sorted and filtered.
Public property Filter Gets or sets a callback that is used to determine whether an item is suited for inclusion in the view.
Public property GroupDescriptions Gets a collection of GroupDescription objects that describe how the items in the collection are grouped in the view.
Public property Groups Gets the top-level groups, constructed according to the descriptions specified in the GroupDescriptions property.
Public property IsAddingNew Gets a value that indicates whether an AddNew transaction is in progress.
Public property IsCurrentAfterLast Gets a value that indicates whether the CurrentItem of the view is beyond the end of the collection.
Public property IsCurrentBeforeFirst Gets a value that indicates whether the CurrentItem of the view is before the start of the collection.
Public property IsEditingItem Gets a value that indicates whether an EditItem transaction is in progress.
Public property IsEmpty Gets a value that indicates whether the view is empty.
Public property IsPageChanging Gets a value that indicates whether the page index is changing.
Public property Item Gets the item at the specified index.
Public property ItemCount Gets the minimum number of items known to be in the source collection that satisfy the current filter.
Public property NeedsRefresh Gets a value that indicates whether this view needs to be refreshed.
Public property NewItemPlaceholderPosition Gets or sets a value that indicates whether to include a new item placeholder in the collection view, and where to include it.
Public property PageIndex Gets the zero-based index of the current page.
Public property PageSize Gets or sets the number of items to display on a page.
Public property SortDescriptions Gets a collection of SortDescription objects that describe how the items in the collection are sorted in the view.
Public property SourceCollection Gets the IEnumerable collection underlying this view.
Public property TotalItemCount Gets the total number of items in the view before paging is applied.
Top
  NameDescription
Public method AddNew Adds a new item to the underlying collection.
Public method CancelEdit Ends the edit transaction and, if it is possible, restores the original value of the item.
Public method CancelNew Ends the add transaction and discards the pending new item.
Public method CommitEdit Ends the edit transaction and saves the pending changes.
Public method CommitNew Ends the add transaction and saves the pending new item.
Public method Contains Returns a value that indicates whether the specified item belongs to this collection view.
Public method DeferRefresh Enters a defer cycle that you can use to merge changes to the view and delay automatic refresh.
Public method EditItem Begins an edit transaction on the specified item.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public method GetEnumerator Returns an IEnumerator object that you can use to enumerate the items in the view.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetItemAt Gets the item at the specified zero-based index in this PagedCollectionView, after the source collection is filtered, sorted, and paged.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method IndexOf Returns the zero-based index at which the specified item is located.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method MoveCurrentTo Sets the specified item to be the CurrentItem in the view.
Public method MoveCurrentToFirst Sets the first item in the view as the CurrentItem.
Public method MoveCurrentToLast Sets the last item in the view as the CurrentItem.
Public method MoveCurrentToNext Set the item after the CurrentItem in the view as the CurrentItem.
Public method MoveCurrentToPosition Sets the item at the specified index to be the CurrentItem in the view.
Public method MoveCurrentToPrevious Sets the item before the CurrentItem in the view as the CurrentItem.
Public method MoveToFirstPage Sets the first page as the current page.
Public method MoveToLastPage Sets the last page as the current page.
Public method MoveToNextPage Moves to the page after the current page.
Public method MoveToPage Moves to the page at the specified index.
Public method MoveToPreviousPage Moves to the page before the current page.
Public method PassesFilter Returns a value that indicates whether the specified item in the underlying collection belongs to the view after filters are applied.
Public method Refresh Re-creates the view.
Public method Remove Removes the specified item from the collection.
Public method RemoveAt Removes the item at the specified position from the collection.
Public method ToString Returns a String that represents the current Object. (Inherited from Object.)
Top
  NameDescription
Public event CollectionChanged Occurs when the view has changed.
Public event CurrentChanged Occurs after the CurrentItem has changed.
Public event CurrentChanging Occurs when the CurrentItem is changing.
Public event PageChanged Occurs after the PageIndex has changed.
Public event PageChanging Occurs when the PageIndex is changing.
Public event PropertyChanged Occurs after a property value has changed.
Top
  NameDescription
Public Extension Method AsQueryable Converts an IEnumerable to an IQueryable. (Defined by Queryable.)
Public Extension Method Cast<TResult> Converts the elements of an IEnumerable to the specified type. (Defined by Enumerable.)
Public Extension Method OfType<TResult> Filters the elements of an IEnumerable based on a specified type. (Defined by Enumerable.)
Top
  NameDescription
Explicit interface implemetation Private method IEnumerable.GetEnumerator Returns an enumerator that iterates through a collection.
Explicit interface implemetation Private event INotifyCollectionChanged.CollectionChanged Occurs when the items list of the collection has changed, or the collection is reset.
Explicit interface implemetation Private event INotifyPropertyChanged.PropertyChanged Occurs when a property value changes.
Top
You use a PagedCollectionView to provide grouping, sorting, filtering, and paging functionality for any collection that implements the IEnumerable interface. The DataPager control provides a convenient user interface for controlling paging with a PagedCollectionView.
You can think of a collection view as a layer on top of a binding source collection that allows you to navigate and display the collection based on sort, filter, and group queries, all without having to manipulate the underlying source collection itself.
The following code example demonstrates how to use a PagedCollectionView with a DataPager to page through data displayed in a ListBox. The List<T> that stores the data is wrapped in a PagedCollectionView, which provides paging functionality. Both the DataPager and the ListBox use the PagedCollectionView as their data source.
<!-- NOTE: 
  By convention, the sdk prefix indicates a URI-based XAML namespace declaration 
  for Silverlight SDK client libraries. This namespace declaration is valid for 
  Silverlight 4 only. In Silverlight 3, you must use individual XAML namespace 
  declarations for each CLR assembly and namespace combination outside the scope 
  of the default Silverlight XAML namespace. For more information, see the help 
  topic "Prefixes and Mappings for Silverlight Libraries". 
-->
<UserControl x:Class="DataPagerSample.MainPage"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
    <Grid x:Name="LayoutRoot" Width="400">
        <StackPanel Margin="10">
            <sdk:DataPager x:Name="dataPager1"
                            PageSize="5"
                            AutoEllipsis="True"
                            NumericButtonCount="3"
                            DisplayMode="FirstLastPreviousNextNumeric"
                            IsTotalItemCountFixed="True"/>

            <ListBox x:Name="listBox1" />
        </StackPanel>
    </Grid>
</UserControl>


using System;
using System.Collections.Generic;
using System.Windows.Controls;
using System.Windows.Data;

namespace DataPagerSample
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            List<String> itemList = new List<String>();
            // Generate some items to add to the list.
            for (int i = 1; i <= 33; i++)
            {
                System.Text.StringBuilder sb = new System.Text.StringBuilder("Item ");
                sb.Append(i.ToString());
                itemList.Add(sb.ToString());
            }
            // Wrap the itemList in a PagedCollectionView for paging functionality
            PagedCollectionView itemListView = new PagedCollectionView(itemList);

            // Set the DataPager and ListBox to the same data source.
            dataPager1.Source = itemListView;
            listBox1.ItemsSource = itemListView;
        }
    }
}


Silverlight

Supported in: 4, 3
For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Community Content Add
Annotations FAQ
Page view tracker

Pagind in Silverlight using PagedCollectionView


 Private Sub MainPage_Loaded(ByVal sender As Object, ByVal e As


System.Windows.RoutedEventArgs) Handles Me.Loaded
Dim x As New List(Of String)
x.Add("aaa")
x.Add("bbb")
x.Add("ccc")
x.Add("ddd")
x.Add("eee")
x.Add("fff")
Dim y As New System.Windows.Data.PagedCollectionView(x)
DataGrid1.ItemsSource = y
DataPager1.Source = y
End Sub

Thursday, April 7, 2011

CASE in UPDATE : How will change M to F in a table ?

create
id
gender
)
 
table test ( int identity(1,1) , nvarchar(10)insert test( gender) values (
 
'M') , ('F') , ('F') , ('M') , ('M') , ('F') insert test( gender) select 'M' union all select 'F' union all select 'M' union all select 'M' union all select 'F' union all select
 
'F' select * into test1 from test select a.id ,a.gender , b.gender from test a join test1 b on a.id = b.id update test set gender = case
when gender = 'M' then 'F' else 'M'end

Wednesday, April 6, 2011

Creating a .jpg file using System.Drawing , saving it and then sending it to .apsx page


http://www.aspnettutorials.com/tutorials/graphics/Drawing-Csharp.aspx



Imports System.DrawingImports System.Drawing.ImagingImports System.Drawing.TextPartial




objBitmap =
objGraphics = Graphics.FromImage(objBitmap)
objGraphics.Clear(Color.White)


objGraphics.DrawEllipse(p, rect)



objGraphics.FillPie(b1, rect, 0.0F, 60.0F)
objGraphics.FillPie(b2, rect, 60.0F, 150.0F)
objGraphics.FillPie(b3, rect, 210.0F, 150.0F)



objGraphics.DrawString(
objBitmap.Save(Response.OutputStream, ImageFormat.Gif)
objBitmap.Save(Server.MapPath(
objBitmap.Dispose()
objGraphics.Dispose()


End







Class _DefaultInherits System.Web.UI.PageProtected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.LoadDim objBitmap As BitmapDim objGraphics As GraphicsNew Bitmap(400, 440)Dim p As New Pen(Color.Yellow, 0)Dim rect As New Rectangle(10, 10, 280, 280)Dim b1 As Brush = New SolidBrush(Color.Red)Dim b2 As Brush = New SolidBrush(Color.Green)Dim b3 As Brush = New SolidBrush(Color.Blue)Dim fontfml As FontFamily = New FontFamily(GenericFontFamilies.Serif)Dim font As Font = New Font(fontfml, 16)Dim brush As SolidBrush = New SolidBrush(Color.Blue)"Drawing Graphics", font, brush, 70, 300)"x.jpg"), ImageFormat.Jpeg)End Sub Class

Tuesday, April 5, 2011

Sending Email














using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net.Mail;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        //See "Image.png" attached here to see how the mail looks when received.
        SmtpClient smtpClient = new SmtpClient();
        MailMessage message = new MailMessage();

            MailAddress fromAddress = new MailAddress("Marketing@Sales.net" , "An Elegant SalesMan" /*Display name, will be displayed in "From" in mailbox*/ );
            // You can specify the host name or ipaddress of your server
            // Default in IIS will be localhost
            smtpClient.Host = "smtp.saha.net";
            //Default port will be 25
            smtpClient.Port = 25;
            //From address will be given as a MailAddress Object
            message.From = fromAddress;
            // To address collection of MailAddress
            message.To.Add("rajesh@saha.net");
            message.Subject = "Test Mail";
            // CC and BCC optional
            // MailAddressCollection class is used to send the email to various users
            // You can specify Address as new MailAddress("admin1@yoursite.com")
            //message.CC.Add("admin1@yoursite.com");
            //message.CC.Add("admin2@yoursite.com");
            // You can specify Address directly as string
            //message.Bcc.Add(new MailAddress("admin3@yoursite.com"));
            ///message.Bcc.Add(new MailAddress("admin4@yoursite.com"));
            //Body can be Html or text format
            //Specify true if it  is html message
            message.IsBodyHtml = false;
            // Message body content
            message.Body = "rajesh\nchandras\n\n\n\ntest";
        
            // Send SMTP mail
            smtpClient.Send(message);
           
    }
}

Wednesday, March 30, 2011

JavaScript Validations

http://rgagnon.com/jsdetails/js-0063.html

The test page is http://rgagnon.com/examples/jsregexp.html


Use regular expressions to validate/format a string

This is an impressive collection (that I found somehere on the Net) of various functions to validate or format string in Javascript. The code is very compact.

/****************************************************************
FILE: RegExpValidate.js

DESCRIPTION: This file contains a library of validation functions
  using javascript regular expressions.  Library also contains 
  functions that reformat fields for display or for storage.


  VALIDATION FUNCTIONS:

  validateEmail - checks format of email address
    validateUSPhone - checks format of US phone number
    validateNumeric - checks for valid numeric value
  validateInteger - checks for valid integer value
    validateNotEmpty - checks for blank form field
  validateUSZip - checks for valid US zip code
  validateUSDate - checks for valid date in US format
  validateValue - checks a string against supplied pattern

  FORMAT FUNCTIONS:

  rightTrim - removes trailing spaces from a string
  leftTrim - removes leading spaces from a string
  trimAll - removes leading and trailing spaces from a string
  removeCurrency - removes currency formatting characters (), $
  addCurrency - inserts currency formatting characters
  removeCommas - removes comma separators from a number
  addCommas - adds comma separators to a number
  removeCharacters - removes characters from a string that match 
  passed pattern


AUTHOR: Karen Gayda

DATE: 03/24/2000
*******************************************************************/

function validateEmail( strValue) {
/************************************************
DESCRIPTION: Validates that a string contains a
  valid email pattern.

 PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS: Accounts for email with country appended
  does not validate that email contains valid URL
  type (.com, .gov, etc.) or valid country suffix.
*************************************************/
var objRegExp  =
 /(^[a-z]([a-z_\.]*)@([a-z_\.]*)([.][a-z]{3})$)|(^[a-z]([a-z_\.]*)@
  ([a-z_\.]*)(\.[a-z]{3})(\.[a-z]{2})*$)/i;

  //check for valid email
  return objRegExp.test(strValue);
}

function validateUSPhone( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains valid
  US phone pattern.
  Ex. (999) 999-9999 or (999)999-9999

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
*************************************************/
  var objRegExp  = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;

  //check for valid us phone with or without space between
  //area code
  return objRegExp.test(strValue);
}

function  validateNumeric( strValue ) {
/*****************************************************************
DESCRIPTION: Validates that a string contains only valid numbers.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
******************************************************************/
  var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

  //check for numeric characters
  return objRegExp.test(strValue);
}

function validateInteger( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid integer number.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
**************************************************/
  var objRegExp  = /(^-?\d\d*$)/;

  //check for integer characters
  return objRegExp.test(strValue);
}

function validateNotEmpty( strValue ) {
/************************************************
DESCRIPTION: Validates that a string is not all
  blank (whitespace) characters.

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.
*************************************************/
   var strTemp = strValue;
   strTemp = trimAll(strTemp);
   if(strTemp.length > 0){
     return true;
   }
   return false;
}

function validateUSZip( strValue ) {
/************************************************
DESCRIPTION: Validates that a string a United
  States zip code in 5 digit format or zip+4
  format. 99999 or 99999-9999

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

*************************************************/
var objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;

  //check for valid US Zipcode
  return objRegExp.test(strValue);
}

function validateUSDate( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid dates with 2 digit month, 2 digit day,
    4 digit year. Date separator can be ., -, or /.
    Uses combination of regular expressions and
    string parsing to validate date.
    Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS:
   Avoids some of the limitations of the Date.parse()
   method such as the date separator character.
*************************************************/
  var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
 
  //check to see if in correct format
  if(!objRegExp.test(strValue))
    return false; //doesn't match pattern, bad date
  else{
    var strSeparator = strValue.substring(2,3) 
    var arrayDate = strValue.split(strSeparator); 
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, 
                        '04' : 30,'05' : 31,
                        '06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,
                        '10' : 31,'11' : 30,'12' : 31}
    var intDay = parseInt(arrayDate[1],10); 

    //check if month value and day value agree
    if(arrayLookup[arrayDate[0]] != null) {
      if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
        return true; //found in lookup table, good date
    }
    
    //check for February (bugfix 20050322)
    //bugfix  for parseInt kevin
    //bugfix  biss year  O.Jp Voutat
    var intMonth = parseInt(arrayDate[0],10);
    if (intMonth == 2) { 
       var intYear = parseInt(arrayDate[2]);
       if (intDay > 0 && intDay < 29) {
           return true;
       }
       else if (intDay == 29) {
         if ((intYear % 4 == 0) && (intYear % 100 != 0) || 
             (intYear % 400 == 0)) {
              // year div by 4 and ((not div by 100) or div by 400) ->ok
             return true;
         }   
       }
    }
  }  
  return false; //any other values, bad date
}

function validateValue( strValue, strMatchPattern ) {
/************************************************
DESCRIPTION: Validates that a string a matches
  a valid regular expression value.

PARAMETERS:
   strValue - String to be tested for validity
   strMatchPattern - String containing a valid
      regular expression match pattern.

RETURNS:
   True if valid, otherwise false.
*************************************************/
var objRegExp = new RegExp( strMatchPattern);

 //check if string matches pattern
 return objRegExp.test(strValue);
}


function rightTrim( strValue ) {
/************************************************
DESCRIPTION: Trims trailing whitespace chars.

PARAMETERS:
   strValue - String to be trimmed.

RETURNS:
   Source string with right whitespaces removed.
*************************************************/
var objRegExp = /^([\w\W]*)(\b\s*)$/;

      if(objRegExp.test(strValue)) {
       //remove trailing a whitespace characters
       strValue = strValue.replace(objRegExp, '$1');
    }
  return strValue;
}

function leftTrim( strValue ) {
/************************************************
DESCRIPTION: Trims leading whitespace chars.

PARAMETERS:
   strValue - String to be trimmed

RETURNS:
   Source string with left whitespaces removed.
*************************************************/
var objRegExp = /^(\s*)(\b[\w\W]*)$/;

      if(objRegExp.test(strValue)) {
       //remove leading a whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}

function trimAll( strValue ) {
/************************************************
DESCRIPTION: Removes leading and trailing spaces.

PARAMETERS: Source string from which spaces will
  be removed;

RETURNS: Source string with whitespaces removed.
*************************************************/
 var objRegExp = /^(\s*)$/;

    //check for all spaces
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }

   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}

function removeCurrency( strValue ) {
/************************************************
DESCRIPTION: Removes currency formatting from
  source string.

PARAMETERS:
  strValue - Source string from which currency formatting
     will be removed;

RETURNS: Source string with commas removed.
*************************************************/
  var objRegExp = /\(/;
  var strMinus = '';

  //check if negative
  if(objRegExp.test(strValue)){
    strMinus = '-';
  }

  objRegExp = /\)|\(|[,]/g;
  strValue = strValue.replace(objRegExp,'');
  if(strValue.indexOf('$') >= 0){
    strValue = strValue.substring(1, strValue.length);
  }
  return strMinus + strValue;
}

function addCurrency( strValue ) {
/************************************************
DESCRIPTION: Formats a number as currency.

PARAMETERS:
  strValue - Source string to be formatted

REMARKS: Assumes number passed is a valid
  numeric value in the rounded to 2 decimal
  places.  If not, returns original value.
*************************************************/
  var objRegExp = /-?[0-9]+\.[0-9]{2}$/;

    if( objRegExp.test(strValue)) {
      objRegExp.compile('^-');
      strValue = addCommas(strValue);
      if (objRegExp.test(strValue)){
        strValue = '(' + strValue.replace(objRegExp,'') + ')';
      }
      return '$' + strValue;
    }
    else
      return strValue;
}

function removeCommas( strValue ) {
/************************************************
DESCRIPTION: Removes commas from source string.

PARAMETERS:
  strValue - Source string from which commas will
    be removed;

RETURNS: Source string with commas removed.
*************************************************/
  var objRegExp = /,/g; //search for commas globally

  //replace all matches with empty strings
  return strValue.replace(objRegExp,'');
}

function addCommas( strValue ) {
/************************************************
DESCRIPTION: Inserts commas into numeric string.

PARAMETERS:
  strValue - source string containing commas.

RETURNS: String modified with comma grouping if
  source was all numeric, otherwise source is
  returned.

REMARKS: Used with integers or numbers with
  2 or less decimal places.
*************************************************/
  var objRegExp  = new RegExp('(-?[0-9]+)([0-9]{3})');

    //check for match to search criteria
    while(objRegExp.test(strValue)) {
       //replace original string with first group match,
       //a comma, then second group match
       strValue = strValue.replace(objRegExp, '$1,$2');
    }
  return strValue;
}

function removeCharacters( strValue, strMatchPattern ) {
/************************************************
DESCRIPTION: Removes characters from a source string
  based upon matches of the supplied pattern.

PARAMETERS:
  strValue - source string containing number.

RETURNS: String modified with characters
  matching search pattern removed

USAGE:  strNoSpaces = removeCharacters( ' sfdf  dfd',
                                '\s*')
*************************************************/
 var objRegExp =  new RegExp( strMatchPattern, 'gi' );

 //replace passed pattern matches with blanks
  return strValue.replace(objRegExp,'');
}
You can try it here.
If you want to know more about these MSDN pages :
RegExp Object
Regular Expression Syntax

Common expressions

Date
   /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/     mm/dd/yyyy
   
US zip code
  /(^\d{5}$)|(^\d{5}-\d{4}$)/             99999 or 99999-9999
  
Canadian postal code
  /^\D{1}\d{1}\D{1}\-?\d{1}\D{1}\d{1}$/   Z5Z-5Z5 orZ5Z5Z5
  
Time
  /^([1-9]|1[0-2]):[0-5]\d(:[0-5]\d(\.\d{1,3})?)?$/   HH:MM or HH:MM:SS or HH:MM:SS.mmm
  
IP Address(no check for alid values (0-255))
  /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/ 999.999.999.999
  
Dollar Amount
  /^((\$\d*)|(\$\d*\.\d{2})|(\d*)|(\d*\.\d{2}))$/ 100, 100.00, $100 or $100.00
  
Social Security Number
  /^\d{3}\-?\d{2}\-?\d{4}$/   999-99-9999 or999999999
  
Canadian Social Insurance Number
  /^\d{9}$/ 999999999

Comparing features of LangGraph vs CrewAI

LangGraph Orchestration vs CrewAI Orchestration The following table compares LangGraph and CrewAI orchestration across their menta...